Skip to content
Snippets Groups Projects
Commit b4c5a69b authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Add STTL export phase using Corese-Python and Py4j

parent 6d50750d
No related branches found
No related tags found
No related merge requests found
File added
......@@ -2,6 +2,7 @@ cssselect==1.2.0
esprima==4.0.1
isodate==0.6.1
lxml==5.2.2
py4j==0.10.9.7
pyparsing==3.1.2
rdflib==7.0.0
six==1.16.0
......
# type: ignore
# (because py4j has no stubs and pretty much breaks type checkers)
import atexit
import subprocess
from time import sleep
from py4j.java_gateway import JavaGateway
from common import *
gateway_cmd = ["java", "-jar", "corese-library-python-4.5.0.jar"]
# Stop Java gateway when exiting script
def exit_handler(gateway):
if gateway is not None:
gateway.shutdown()
print("\nGateway server stopped.")
else:
subprocess.run(["pkill", "--exact", "--full", " ".join(gateway_cmd)])
print("\nGateway server killed.")
def main():
# Start Java gateway
java_process = subprocess.Popen(gateway_cmd)
sleep(1)
gateway = JavaGateway()
atexit.register(exit_handler, gateway)
# Import Java classes
Graph = gateway.jvm.fr.inria.corese.core.Graph
Load = gateway.jvm.fr.inria.corese.core.load.Load
Property = gateway.jvm.fr.inria.corese.core.util.Property
QueryProcess = gateway.jvm.fr.inria.corese.core.query.QueryProcess
RDF = gateway.jvm.fr.inria.corese.core.logic.RDF
Transformer = gateway.jvm.fr.inria.corese.core.transform.Transformer
# Create graph, load Turtle files for schema and content
graph = Graph()
ld = Load.create(graph)
Property.set(Property.Value.DISABLE_OWL_AUTO_IMPORT, True)
ld.parse(SCHEMA_FILE)
ld.parse(RESULT_FILE)
# Run STTL transformation
tr = Transformer.create(graph, MODULE_DIR + "/../templates/")
result = tr.transform()
print(result)
if __name__ == "__main__":
main()
......@@ -31,7 +31,7 @@ def create_graph() -> Graph:
def export_graph(g: Graph):
"""Exports the graph to `OUT_FILE`, with OWL imports to include
"""Exports the graph to `RESULT_FILE`, with OWL imports to include
the schema file when loaded as an ontology
"""
this_onto = content_ontology_uri
......
import export
import extract
def main():
extract.main()
# transform.main()
# export.main()
export.main()
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment