relrae 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
relrae-0.9.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 George Hannah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
relrae-0.9.0/PKG-INFO ADDED
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: relrae
3
+ Version: 0.9.0
4
+ Summary: Relationship Extraction, Labelling, Refinement, and Evaluation
5
+ Author: George Hannah
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/KE-UniLiv/RELRaE_2
8
+ Project-URL: Repository, https://github.com/KE-UniLiv/RELRaE_2.git
9
+ Project-URL: Issues, https://github.com/KE-UniLiv/RELRaE_2/issues
10
+ Keywords: knowledge-graphs,ontology,relationship-extraction,semantic-web,xml-schema
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Natural Language :: English
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.12
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: lxml
25
+ Requires-Dist: numpy
26
+ Requires-Dist: pydantic
27
+ Requires-Dist: PyYAML
28
+ Requires-Dist: rdflib
29
+ Requires-Dist: xmlschema
30
+ Dynamic: license-file
31
+
32
+ # RELRaE 2.0
33
+
34
+ Relationship Extraction, Labelling, Refinement, and Evaluation (RELRaE) is a
35
+ Python framework for generating and refining RDF ontologies from XML Schema
36
+ definitions.
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.12 or newer
41
+
42
+ ## Installation
43
+
44
+ Install the latest published release with pip:
45
+
46
+ ```console
47
+ python -m pip install relrae
48
+ ```
49
+
50
+ To install a local checkout for development:
51
+
52
+ ```console
53
+ python -m pip install -e .
54
+ ```
55
+
56
+ ## Create a project
57
+
58
+ Run the initializer inside a new project directory:
59
+
60
+ ```console
61
+ relrae init
62
+ ```
63
+
64
+ You can also provide the destination explicitly:
65
+
66
+ ```console
67
+ relrae init path/to/project
68
+ ```
69
+
70
+ This creates the following structure without overwriting existing files:
71
+
72
+ ```text
73
+ relrae_components/
74
+ ├── config/
75
+ │ ├── LLM_ref_conf.txt
76
+ │ ├── RuBREx_conf.txt
77
+ │ └── pipeline_conf.txt
78
+ ├── output/
79
+ ├── rules/
80
+ │ └── SXPF_General_1_0.yaml
81
+ └── schema/
82
+ ```
83
+
84
+ Place an XML Schema file in `relrae_components/schema/`, then configure its
85
+ filename, namespace, prefix, ontology name, and pipeline modules in
86
+ `relrae_components/config/pipeline_conf.txt`.
87
+
88
+ ## Python API
89
+
90
+ The main pipeline class is available from the package root:
91
+
92
+ ```python
93
+ from relrae import RELRaE
94
+ ```
95
+
96
+ See [`scripts/test_pipeline.py`](scripts/test_pipeline.py) for an end-to-end
97
+ pipeline example using the sample data under `examples/`.
98
+
99
+ ## Building distributions
100
+
101
+ Install the build frontend and create both source and wheel distributions:
102
+
103
+ ```console
104
+ python -m pip install build
105
+ python -m build
106
+ ```
107
+
108
+ The publication artifacts are written to `dist/`. Check them before upload:
109
+
110
+ ```console
111
+ python -m pip install twine
112
+ python -m twine check dist/*
113
+ ```
114
+
115
+ ## Project links
116
+
117
+ - [Source repository](https://github.com/KE-UniLiv/RELRaE_2)
118
+ - [Issue tracker](https://github.com/KE-UniLiv/RELRaE_2/issues)
119
+
120
+ ## License
121
+
122
+ RELRaE is distributed under the [MIT License](LICENSE).
relrae-0.9.0/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # RELRaE 2.0
2
+
3
+ Relationship Extraction, Labelling, Refinement, and Evaluation (RELRaE) is a
4
+ Python framework for generating and refining RDF ontologies from XML Schema
5
+ definitions.
6
+
7
+ ## Requirements
8
+
9
+ - Python 3.12 or newer
10
+
11
+ ## Installation
12
+
13
+ Install the latest published release with pip:
14
+
15
+ ```console
16
+ python -m pip install relrae
17
+ ```
18
+
19
+ To install a local checkout for development:
20
+
21
+ ```console
22
+ python -m pip install -e .
23
+ ```
24
+
25
+ ## Create a project
26
+
27
+ Run the initializer inside a new project directory:
28
+
29
+ ```console
30
+ relrae init
31
+ ```
32
+
33
+ You can also provide the destination explicitly:
34
+
35
+ ```console
36
+ relrae init path/to/project
37
+ ```
38
+
39
+ This creates the following structure without overwriting existing files:
40
+
41
+ ```text
42
+ relrae_components/
43
+ ├── config/
44
+ │ ├── LLM_ref_conf.txt
45
+ │ ├── RuBREx_conf.txt
46
+ │ └── pipeline_conf.txt
47
+ ├── output/
48
+ ├── rules/
49
+ │ └── SXPF_General_1_0.yaml
50
+ └── schema/
51
+ ```
52
+
53
+ Place an XML Schema file in `relrae_components/schema/`, then configure its
54
+ filename, namespace, prefix, ontology name, and pipeline modules in
55
+ `relrae_components/config/pipeline_conf.txt`.
56
+
57
+ ## Python API
58
+
59
+ The main pipeline class is available from the package root:
60
+
61
+ ```python
62
+ from relrae import RELRaE
63
+ ```
64
+
65
+ See [`scripts/test_pipeline.py`](scripts/test_pipeline.py) for an end-to-end
66
+ pipeline example using the sample data under `examples/`.
67
+
68
+ ## Building distributions
69
+
70
+ Install the build frontend and create both source and wheel distributions:
71
+
72
+ ```console
73
+ python -m pip install build
74
+ python -m build
75
+ ```
76
+
77
+ The publication artifacts are written to `dist/`. Check them before upload:
78
+
79
+ ```console
80
+ python -m pip install twine
81
+ python -m twine check dist/*
82
+ ```
83
+
84
+ ## Project links
85
+
86
+ - [Source repository](https://github.com/KE-UniLiv/RELRaE_2)
87
+ - [Issue tracker](https://github.com/KE-UniLiv/RELRaE_2/issues)
88
+
89
+ ## License
90
+
91
+ RELRaE is distributed under the [MIT License](LICENSE).
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "relrae"
7
+ dynamic = ["version"]
8
+ description = "Relationship Extraction, Labelling, Refinement, and Evaluation"
9
+ readme = { file = "README.md", content-type = "text/markdown" }
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.12"
13
+ authors = [
14
+ { name = "George Hannah" },
15
+ ]
16
+ keywords = [
17
+ "knowledge-graphs",
18
+ "ontology",
19
+ "relationship-extraction",
20
+ "semantic-web",
21
+ "xml-schema",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 4 - Beta",
25
+ "Environment :: Console",
26
+ "Intended Audience :: Developers",
27
+ "Intended Audience :: Science/Research",
28
+ "Natural Language :: English",
29
+ "Operating System :: OS Independent",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
33
+ "Topic :: Software Development :: Libraries :: Python Modules",
34
+ ]
35
+ dependencies = [
36
+ "lxml",
37
+ "numpy",
38
+ "pydantic",
39
+ "PyYAML",
40
+ "rdflib",
41
+ "xmlschema",
42
+ ]
43
+
44
+ [project.urls]
45
+ Homepage = "https://github.com/KE-UniLiv/RELRaE_2"
46
+ Repository = "https://github.com/KE-UniLiv/RELRaE_2.git"
47
+ Issues = "https://github.com/KE-UniLiv/RELRaE_2/issues"
48
+
49
+ [project.scripts]
50
+ relrae = "relrae.cli:main"
51
+
52
+ [tool.setuptools]
53
+ include-package-data = true
54
+
55
+ [tool.setuptools.packages.find]
56
+ where = ["src"]
57
+ include = ["relrae*"]
58
+
59
+ [tool.setuptools.package-data]
60
+ relrae = ["relrae_components/config/*.txt", "relrae_components/rules/*.yaml"]
61
+
62
+ [tool.setuptools.dynamic]
63
+ version = { attr = "relrae._version.__version__" }
relrae-0.9.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,91 @@
1
+ from rdflib import Graph, Namespace
2
+ from rdflib.namespace import RDF, RDFS, OWL
3
+ import xmlschema
4
+ from pathlib import Path
5
+
6
+
7
+ from .modules.RuBREx import RuBREx
8
+ from .modules.LLM_Ref import LLMRefinement
9
+ from .modules.human_fix import HumanFix
10
+ from .utils import get_now
11
+
12
+
13
+ class RELRaE:
14
+
15
+ def __init__(self, onto_name, schema, namespace, prefix, config,
16
+ components_root="relrae_components", output_root="output"):
17
+ self.components_root = Path(components_root)
18
+ self.output_root = Path(output_root)
19
+ schema_path = self.components_root / "schema" / schema
20
+ self.schema = xmlschema.XMLSchema(schema_path)
21
+ self.namespace = Namespace(namespace)
22
+ self.prefix = prefix
23
+ self.onto_name = onto_name
24
+ self.onto = Graph()
25
+ self.errors = []
26
+ self.config = config
27
+ self.configs = [{"Pipeline": config}]
28
+ self.logs = {}
29
+
30
+ self.onto.bind('rdf', RDF)
31
+ self.onto.bind('rdfs', RDFS)
32
+ self.onto.bind('owl', OWL)
33
+ self.onto.bind(self.prefix, self.namespace)
34
+
35
+ def RuBREx(self):
36
+ m_rubrex = RuBREx(
37
+ self.schema, self.onto, self.prefix, self.namespace,
38
+ self.components_root,
39
+ )
40
+ m_rubrex.match_concepts()
41
+ m_rubrex.schema_coverage()
42
+
43
+ self.configs.append({"RuBREx": m_rubrex.config})
44
+ self.logs["RuBREx"] = m_rubrex.log
45
+ # NOTE: Consider the module complete
46
+ self.onto = self.onto + m_rubrex.onto
47
+ self.errors.append(m_rubrex.errors)
48
+
49
+ def LLM_Refinement_Loop(self):
50
+ m_LLM_ref = LLMRefinement(
51
+ self.schema, self.onto, self.prefix, self.namespace,
52
+ self.components_root)
53
+ m_LLM_ref.evaluate_relations()
54
+ self.errors.append(m_LLM_ref.errors)
55
+
56
+ def human_fix(self):
57
+ # TODO:
58
+ m_human_fix = HumanFix(
59
+ self.schema, self.onto, self.prefix, self.namespace,
60
+ self.components_root, self.errors, self.config["modules"]
61
+ )
62
+ m_human_fix.set_user_info()
63
+ m_human_fix.fix_errors()
64
+ m_human_fix.concepts_to_add_output(path)
65
+
66
+ def write_logs(self, path):
67
+ for key, values in self.logs.items():
68
+ with (path / f"{key}.txt").open("w", encoding="utf-8") as f:
69
+ for line in values:
70
+ f.write(line + "\n")
71
+
72
+ def write_metadata(self, path):
73
+ with (path / "metadata.txt").open("w", encoding="utf-8") as f:
74
+ for config in self.configs:
75
+ for section, values in config.items():
76
+ f.write(f"{section}\n\n")
77
+ for key, value in values.items():
78
+ f.write(f"{key}: {value}\n")
79
+ f.write("\n\n")
80
+
81
+ def serialise(self):
82
+ timestamp = get_now().replace(":", "-")
83
+ main_path = self.output_root / f"{self.onto_name}{timestamp}"
84
+ log_path = main_path / "logs"
85
+ log_path.mkdir(parents=True)
86
+ self.write_logs(log_path)
87
+ self.write_metadata(main_path)
88
+ self.onto.serialize(
89
+ destination=main_path / f"{self.onto_name}.ttl",
90
+ format="ttl",
91
+ )
@@ -0,0 +1,6 @@
1
+ """Public package interface for RELRaE."""
2
+
3
+ from ._version import __version__
4
+ from .RELRaE import RELRaE
5
+
6
+ __all__ = ["RELRaE", "__version__"]
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,3 @@
1
+ """The single source of truth for the RELRaE package version."""
2
+
3
+ __version__ = "0.9.0"
@@ -0,0 +1,65 @@
1
+ import argparse
2
+ from importlib.resources import files
3
+ from pathlib import Path
4
+ import shutil
5
+
6
+
7
+ COMPONENT_DIRECTORIES = ("config", "rules", "schema", "output")
8
+
9
+
10
+ def _copy_defaults(source, destination):
11
+ """Copy packaged defaults without replacing user-edited files."""
12
+ for resource in source.iterdir():
13
+ # Finder metadata is not part of a RELRaE project, even if it happens
14
+ # to be present in a source checkout.
15
+ if resource.name.startswith("."):
16
+ continue
17
+
18
+ target = destination / resource.name
19
+ if resource.is_dir():
20
+ target.mkdir(exist_ok=True)
21
+ _copy_defaults(resource, target)
22
+ elif not target.exists():
23
+ with resource.open("rb") as source_file, target.open("xb") as target_file:
24
+ shutil.copyfileobj(source_file, target_file)
25
+
26
+
27
+ def initialise_project(project_root=None):
28
+ """Create a RELRaE project beneath *project_root* (the cwd by default).
29
+
30
+ Existing files are intentionally left untouched, making ``relrae init``
31
+ safe to run again after configuration files have been customised.
32
+ """
33
+ project_root = Path.cwd() if project_root is None else Path(project_root)
34
+ components_root = project_root / "relrae_components"
35
+
36
+ project_root.mkdir(parents=True, exist_ok=True)
37
+ for directory in COMPONENT_DIRECTORIES:
38
+ (components_root / directory).mkdir(parents=True, exist_ok=True)
39
+
40
+ packaged_defaults = files("relrae").joinpath("relrae_components")
41
+ _copy_defaults(packaged_defaults, components_root)
42
+
43
+ print(f"Initialised RELRaE project in {components_root}")
44
+ return components_root
45
+
46
+
47
+ def main():
48
+ parser = argparse.ArgumentParser()
49
+ subparsers = parser.add_subparsers(dest="command")
50
+
51
+ init_parser = subparsers.add_parser(
52
+ "init", help="create a RELRaE project in the current directory"
53
+ )
54
+ init_parser.add_argument(
55
+ "directory",
56
+ nargs="?",
57
+ default=Path.cwd(),
58
+ type=Path,
59
+ help="project directory (default: current directory)",
60
+ )
61
+
62
+ args = parser.parse_args()
63
+
64
+ if args.command == "init":
65
+ initialise_project(args.directory)