I have been working on various relationship extraction models in python and all the relationships are currently saved in dataframes or csv files. Eventually I would like to create an RDF graph. Since I am working in python I was going to create the RDF using RDFlib and read the RDF into Apache Jena into a model that I can query. Is this a good workflow or is there a better way?
Apache Jena is an open source Semantic Web framework for Java. It provides an API to extract data from and write to RDF graphs. The graphs are represented as an abstract "model". A model can be sourced with data from files, databases, URLs or a combination of these.
Apache Jena Fuseki is a SPARQL server. It can run as a operating system service, as a Java web application (WAR file), and as a standalone server.
Link to download apache Jena: https://jena.apache.org/download/inde... Link to download Java: https://www.java.com/en/download/manu...
Quite late, but as I ran into a similar problem, heres my way how to talk to Jena TDB from python.
You could also make use of JayDeBeApi and the official Jena TDB JDBC Driver. You have to make sure that the JDBC Driver is available in the Java classpath.
import jaydebeapi
jclass = "org.apache.jena.jdbc.JenaJDBC"
conn_string = "jdbc:jena:tdb:location=/path/to/tdbstore"
conn = jaydebeapi.connect(jclass, conn_string)
cursor = conn.cursor()
query = """
SELECT DISTINCT ?a
WHERE {
?a ?b ?b .
}
"""
cursor.execute(query)
# do something with the results
cursor.close()
conn.close()
You can also add &must-exist=true|false
to conn_string
denoting whether the store must exist or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With