mirror of
https://github.com/docling-project/docling-parse.git
synced 2026-11-18 20:27:35 +00:00
adding python resources
Signed-off-by: Peter Staar <taa@zurich.ibm.com>
This commit is contained in:
1 parent
8c3e467c62
commit
eada2fb7d6
5 files changed
+132
-97
No files matched your search
+1
-25
@@ -12,43 +12,19 @@ Email: {taa, dol, cau, ttt}@zurich.ibm.com
|
||||
Date: 18/08/2017
|
||||
**********************************************************/
|
||||
|
||||
|
||||
#include <utf8/utf8.h>
|
||||
|
||||
#include "include_libs.h"
|
||||
|
||||
//#include "comp_library.h"
|
||||
#include <utils.h>
|
||||
#include <utils/meta_library.h>
|
||||
#include <utils/logging_library.h>
|
||||
#include <utils/string_library.h>
|
||||
#include <utils/system_library.h>
|
||||
|
||||
//#include <profiler_library.h>
|
||||
|
||||
//#include <function_library.h>
|
||||
#include <utils/container_library.h>
|
||||
|
||||
#include <utils/IO_library.h>
|
||||
/*
|
||||
#include <IO_library/IO_types.h>
|
||||
#include <IO_library/ROUTINES/IO_routines.h>
|
||||
|
||||
#include <IO_library/template_reader.h>
|
||||
#include <IO_library/template_writer.h>
|
||||
|
||||
#include <IO_library/TXT.h>
|
||||
//#include <IO_library/CSV.h>
|
||||
#include <IO_library/JSON.h>
|
||||
//#include <IO_library/BCON.h>
|
||||
*/
|
||||
|
||||
//#include <db_library.h>
|
||||
|
||||
//#include "math_library.h"
|
||||
#include <utils/geometric_objects.h>
|
||||
|
||||
//#include "logging_library.h"
|
||||
|
||||
#include "pdf_library.h"
|
||||
#include "pdf_parser.h"
|
||||
|
||||
|
||||
@@ -4,3 +4,5 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
+12
-72
@@ -3,96 +3,30 @@
|
||||
#ifndef PYBIND_PDF_PARSER_H
|
||||
#define PYBIND_PDF_PARSER_H
|
||||
|
||||
/*
|
||||
#include <utf8/utf8.h>
|
||||
|
||||
#include "include_libs.h"
|
||||
|
||||
#include "meta_library.h"
|
||||
|
||||
//#include "comp_library.h"
|
||||
#include <string_library.h>
|
||||
#include <logging_library.h>
|
||||
#include <system_library.h>
|
||||
|
||||
//#include <profiler_library.h>
|
||||
|
||||
//#include <function_library.h>
|
||||
#include <container_library.h>
|
||||
|
||||
//#include <IO_library.h>
|
||||
#include <IO_library/IO_types.h>
|
||||
#include <IO_library/ROUTINES/IO_routines.h>
|
||||
|
||||
#include <IO_library/template_reader.h>
|
||||
#include <IO_library/template_writer.h>
|
||||
|
||||
#include <IO_library/TXT.h>
|
||||
//#include <IO_library/CSV.h>
|
||||
#include <IO_library/JSON.h>
|
||||
//#include <IO_library/BCON.h>
|
||||
|
||||
//#include <db_library.h>
|
||||
|
||||
//#include "math_library.h"
|
||||
#include "math_library/geometry_library/geometric_objects.h"
|
||||
|
||||
#include "logging_library.h"
|
||||
|
||||
#include "pdf_library.h"
|
||||
#include "pdf_parser.h"
|
||||
|
||||
#include "pdf_interface.h"
|
||||
#include "pdf_interface/parser.h"
|
||||
*/
|
||||
|
||||
#include <utf8/utf8.h>
|
||||
|
||||
#include "include_libs.h"
|
||||
|
||||
//#include "comp_library.h"
|
||||
#include <utils.h>
|
||||
#include <utils/meta_library.h>
|
||||
#include <utils/logging_library.h>
|
||||
#include <utils/string_library.h>
|
||||
#include <utils/system_library.h>
|
||||
|
||||
//#include <profiler_library.h>
|
||||
|
||||
//#include <function_library.h>
|
||||
#include <utils/container_library.h>
|
||||
|
||||
#include <utils/IO_library.h>
|
||||
/*
|
||||
#include <IO_library/IO_types.h>
|
||||
#include <IO_library/ROUTINES/IO_routines.h>
|
||||
|
||||
#include <IO_library/template_reader.h>
|
||||
#include <IO_library/template_writer.h>
|
||||
|
||||
#include <IO_library/TXT.h>
|
||||
//#include <IO_library/CSV.h>
|
||||
#include <IO_library/JSON.h>
|
||||
//#include <IO_library/BCON.h>
|
||||
*/
|
||||
|
||||
//#include <db_library.h>
|
||||
|
||||
//#include "math_library.h"
|
||||
#include <utils/geometric_objects.h>
|
||||
|
||||
//#include "logging_library.h"
|
||||
|
||||
#include "pdf_library.h"
|
||||
#include "pdf_parser.h"
|
||||
|
||||
#include "pdf_interface.h"
|
||||
#include "pdf_interface/parser.h"
|
||||
|
||||
#include "pybind/docling_resources.h"
|
||||
|
||||
namespace docling
|
||||
{
|
||||
class docling_parser//: //public base_log,
|
||||
//public base_resources
|
||||
class docling_parser: public docling_resources
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -108,13 +42,19 @@ namespace docling
|
||||
};
|
||||
|
||||
docling_parser::docling_parser():
|
||||
docling_resources(),
|
||||
interface()
|
||||
{
|
||||
std::string font_data_dir = PDF_DATA_DIR;
|
||||
//std::string font_data_dir = PDF_DATA_DIR;
|
||||
|
||||
logging_lib::info("pdf-parser") << __FILE__ << ":" << __LINE__ << "\t"
|
||||
<< "using default font-data path : " << font_data_dir;
|
||||
std::string font_data_dir = resource_utils::get_resources_dir(true);
|
||||
|
||||
//logging_lib::info("pdf-parser") << __FILE__ << ":" << __LINE__ << "\t"
|
||||
//<< "using default font-data path : " << font_data_dir;
|
||||
|
||||
std::cout << __FILE__ << ":" << __LINE__ << "\t"
|
||||
<< "using default font-data path : " << font_data_dir << "\n";
|
||||
|
||||
pdf_lib::core::object<pdf_lib::core::FONT>::initialize(font_data_dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//-*-C++-*-
|
||||
|
||||
#ifndef PYBIND_DOCLING_RESOURCES_H
|
||||
#define PYBIND_DOCLING_RESOURCES_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
namespace docling
|
||||
{
|
||||
|
||||
class docling_resources
|
||||
{
|
||||
public:
|
||||
|
||||
docling_resources();
|
||||
|
||||
std::string get_resources_path();
|
||||
|
||||
private:
|
||||
|
||||
bool set_resources_path();
|
||||
};
|
||||
|
||||
docling_resources::docling_resources()
|
||||
{
|
||||
set_resources_path();
|
||||
}
|
||||
|
||||
std::string docling_resources::get_resources_path()
|
||||
{
|
||||
return resource_utils::get_resources_dir(true);
|
||||
}
|
||||
|
||||
bool docling_resources::set_resources_path()
|
||||
{
|
||||
// Get the module object of your package
|
||||
PyObject* myPackageModule = PyImport_ImportModule("docling_parse");
|
||||
|
||||
// Get the filename object of the module
|
||||
PyObject* filenameObj = PyModule_GetFilenameObject(myPackageModule);
|
||||
|
||||
// Extract the string value of the filename
|
||||
const char* filename = PyUnicode_AsUTF8(filenameObj);
|
||||
|
||||
std::filesystem::path __init__path(filename);
|
||||
|
||||
std::filesystem::path package_path = __init__path.parent_path();
|
||||
std::filesystem::path resources_path = package_path / resource_utils::resources_relative_path;
|
||||
|
||||
return resource_utils::set_resources_dir(resources_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
//-*-C++-*-
|
||||
|
||||
#ifndef RESOURCE_UTILS_H_
|
||||
#define RESOURCE_UTILS_H_
|
||||
|
||||
class resource_utils
|
||||
{
|
||||
public:
|
||||
|
||||
static inline std::filesystem::path HARDCODED_RESOURCES_DIR = PDF_DATA_DIR;
|
||||
|
||||
const static inline std::filesystem::path package_name = "docling_parse";
|
||||
const static inline std::filesystem::path resources_relative_path = "resources";
|
||||
|
||||
public:
|
||||
|
||||
static bool set_resources_dir(std::filesystem::path path);
|
||||
|
||||
static std::filesystem::path get_resources_dir(bool verify=true);
|
||||
|
||||
private:
|
||||
|
||||
static inline std::filesystem::path ROOT_DIR = ROOT_PATH;
|
||||
static inline std::filesystem::path PACKAGE_DIR = ROOT_PATH / package_name;
|
||||
static inline std::filesystem::path RESOURCES_DIR = PACKAGE_DIR / resources_relative_path;
|
||||
};
|
||||
|
||||
bool resource_utils::set_resources_dir(std::filesystem::path path)
|
||||
{
|
||||
RESOURCES_DIR = path;
|
||||
|
||||
std::cout << __FILE__ << ":" << __LINE__ << "\t"
|
||||
<< "updated the resources-dir" << "\n";
|
||||
|
||||
if(std::filesystem::exists(RESOURCES_DIR))
|
||||
{
|
||||
PACKAGE_DIR = RESOURCES_DIR.parent_path();
|
||||
ROOT_DIR = PACKAGE_DIR.parent_path();
|
||||
|
||||
//LOG_S(INFO) << "updated resourrces-dir: " << RESOURCES_DIR;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOG_S(ERROR) << "updated resources-dir to non-existant path: "
|
||||
//<< path << " at " << __FILE__ << ":" << __LINE__;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path resource_utils::get_resources_dir(bool verify)
|
||||
{
|
||||
if(verify and (not std::filesystem::exists(RESOURCES_DIR)))
|
||||
{
|
||||
std::cout << __FILE__ << ":" << __LINE__ << "\t"
|
||||
<< "resources-dir does not exist ..." << "\n";
|
||||
}
|
||||
|
||||
return RESOURCES_DIR;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user