Python API for CORESE Semantic Web platform
Corese is a software platform implementing and extending the standards of the Semantic Web. It allows to create, manipulate, parse, serialize, query, reason, and validate RDF data. Corese is based on the W3C standards RDF, RDFS, OWL 2, SPARQL and SHACL. Corese is implemented as a set of open-source Java libraries.
pycorese is a Python package that provides a simple way to integrate the corese-core Java library into Python applications.
pycorese offers an intuitive API to interact with Corese's capabilities such as storage, SPARQL engine, RDFS and OWL reasoning, and SHACL validation.
pycorese unlocks the potential of Semantic Web stack for applications such as semantic data analysis, knowledge graph construction, and Machine Learning.
pycorese can be easily installed via pip
:
pip install pycorese
This process installs both the Python wrappers and the Corese Java libraries. To run the Java libraries, ensure that Java is installed on your system. A Java Runtime Environment (JRE) version 11 or higher is required. If Java is not installed, visit the official website for installation instructions.
To install pycorese from the current GitHub repository follow the instructions from INSTALL.md.
Here is a simple example of how to use pycorese to load and query RDF data:
from pycorese.api import CoreseAPI
corese = CoreseAPI()
corese.loadCorese()
# Load RDF data
data = """
@prefix ex: <http://example.org/> .
ex:John ex:hasFriend ex:Jane, ex:Jill.
ex:Jane ex:age 25 .
ex:Jill ex:age 40 .
"""
graph = corese.loadRDF(data)
# Query the data to find out who is John's younger friend
query = """
PREFIX ex: <http://example.org/>
SELECT ?friend ?age
WHERE {
?x ex:age ?ageX .
?x ex:hasFriend ?friend .
?friend ex:age ?age .
FILTER (?ageX > ?age)
}
"""
results = corese.sparqlSelect(graph, query=query, return_dataframe=True)
print(results)
Expected output:
friend age
0 http://example.org/Jane 25
See the GitHub repository for more examples.
- pycorese GitHub pages: https://corese-stack.github.io/corese-python
- Corese GitHub pages: https://corese-stack.github.io/corese-core
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on the GitHub repository.