I have two different ontologies: one for movie genre and another for movie certification. I want to write a query in SPARQL that can find those movies having certification x (say PG-13) and genre y (say action). Both ontologies are different and I upload them in Apache Jena.
These are my ontologies:
PREFIX o2: <http://www.semanticweb.org/administrator/ontologies/2016/11/genre_ontology#>
PREFIX o1: <http://www.semanticweb.org/administrator/ontologies/2016/11/certification_ontology#>
I want to find movies having genre and certification. my query is
SELECT ?x ?z
WHERE {
?x o1:hasCertificationOf ?y.
?z o2:hasGenre ?a.
FILTER regex(str(?y),"R_") FILTER regex (str(?a),"Adventure")
}
here R is Restricted certification
Query result contain movies in x and z, but i only want common movie in x and z?
You should always try to provide a minimal example along with your question.
You might want to look at Multiple triple patterns:
As you see, we use two namespaces (for 2 ontologies). You can reference them like this (before your SPARQL query):
Final query might look like this:
NB: in order to apply multiple graph patterns in a single query, you must use the same variable in those patterns (
?sin the last 2 graph patters).I have no affiliation to the authors, but I think you might benefit from taking https://www.futurelearn.com/courses/linked-data.