1

嗨,我有两个本体和另一个与之对齐的本体。现在我想对对齐本体运行一些 sparql 查询,以从两个本体中获取数据。但我不知道 PREFIX is sparql 应该是什么?以及如何访问属性?

我的第一个本体的一部分是这样的:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [
      <!ENTITY xsd      "http://www.w3.org/2001/XMLSchema#" >
  <!ENTITY rdf      "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
  <!ENTITY rdfs     "http://www.w3.org/2000/01/rdf-schema#" >
  <!ENTITY dc       "http://purl.org/dc/elements/1.1/" > 
  <!ENTITY owl      "http://www.w3.org/2002/07/owl#" > ]>

  <rdf:RDF
  xmlns="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#"
  xml:base="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#"
  xmlns:rdf ="&rdf;"
  xmlns:xsd ="&xsd;"
  xmlns:rdfs    ="&rdfs;"
  xmlns:owl ="&owl;"
  xmlns:dc  ="&dc;">

<owl:Ontology rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl">
<dc:creator>Jérôme Euzenat</dc:creator>
<dc:description>Example for Alignment API advanced turorial</dc:description>
<dc:date>2009-07-06</dc:date>
<dc:date>2014-12-06</dc:date>
<rdfs:label>First ontology</rdfs:label>
<dc:title>ontology1.owl: a fake list of students</dc:title>
<dc:identifier  rdf:datatype="&xsd;anyURI">http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl</dc:identifier>
</owl:Ontology>
<owl:Class rdf:about="#Participante">
<rdfs:label xml:lang="es">Participante</rdfs:label>
</owl:Class>

<owl:Class rdf:about="#Estudiante">
<rdfs:subClassOf rdf:resource="#Participante" />
<rdfs:label xml:lang="es">Estudiante</rdfs:label>
</owl:Class>

<owl:Class rdf:about="#Tutor">
<rdfs:subClassOf rdf:resource="#Participante" />
<rdfs:label xml:lang="es">Professor</rdfs:label>
</owl:Class>

<owl:Class rdf:about="#TutorEstudiante">
<rdfs:subClassOf rdf:resource="#Estudiante" />
<rdfs:subClassOf rdf:resource="#Tutor" />
<rdfs:label xml:lang="es">Professor</rdfs:label>
</owl:Class>

<owl:DatatypeProperty rdf:about="#lastname">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
<rdfs:label xml:lang="es">appelido</rdfs:label>
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#firstname">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
<rdfs:label xml:lang="es">nombre</rdfs:label>
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#gender">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#affiliation">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#city">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#country">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#year">
<rdfs:domain rdf:resource="#Estudiante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#topic">
<rdfs:domain rdf:resource="#Participante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#supervisor">
<rdfs:domain rdf:resource="#Estudiante" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<Estudiante rdf:about="#Fitzgerald">
<lastname>Fitzgerald</lastname>
<firstname>Ella</firstname>
<gender>Female</gender>
<affiliation>Vanilla University of Technology</affiliation>
<city>Vanilla</city>
<country>AT</country>
<year>1</year>
<topic>Semantic Process Mining</topic>
<supervisor>Prof. Giancarlo Cetriolo</supervisor>
</Estudiante>

<Estudiante rdf:about="#Blackey">
<lastname>Blackey</lastname>
<firstname>Art</firstname>
<gender>Male</gender>
<affiliation>University of Albatra</affiliation>
<city>Albatra</city>
<country>ES</country>
<year>1</year>
<topic>Semantic Web applications</topic>
<supervisor>Paola Pomodoro</supervisor>
<supervisor>Pierluiggi Pomodoro</supervisor>
</Estudiante>

我可以像这样运行一些查询并获取数据:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX aa:     <http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#>

SELECT ?fn ?ln ?t ?s
WHERE {
  ?student rdf:type aa:Estudiante .
  ?student aa:firstname  ?fn .
  ?student aa:lastname  ?ln .
OPTIONAL   {   ?student aa:affiliation ?t . }
OPTIONAL   {   ?student aa:supervisor ?s . }
      }

我的第二个本体是这样的:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE rdf:RDF [
      <!ENTITY xsd      "http://www.w3.org/2001/XMLSchema#" >
      <!ENTITY rdf      "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
      <!ENTITY rdfs     "http://www.w3.org/2000/01/rdf-schema#" >
      <!ENTITY dc       "http://purl.org/dc/elements/1.1/" > 
      <!ENTITY owl      "http://www.w3.org/2002/07/owl#" > ]>

      <rdf:RDF
 xmlns="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#"
xml:base="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#"
    xmlns:rdf   ="&rdf;"
    xmlns:xsd   ="&xsd;"
    xmlns:rdfs  ="&rdfs;"
    xmlns:owl   ="&owl;"
    xmlns:dc    ="&dc;">

    <owl:Ontology rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl">
<dc:creator>Jérôme Euzenat</dc:creator>
<dc:description>Example for Alignment API advanced turorial</dc:description>
<dc:date>2009-07-06</dc:date>
<dc:date>2014-12-05</dc:date>
<rdfs:label>Second ontology</rdfs:label>
<dc:title>ontology2.owl: another fake list of students</dc:title>
<dc:identifier         rdf:datatype="&xsd;anyURI">http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl</dc:identifier>
</owl:Ontology>

<owl:Class rdf:about="#Student">
<rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:label xml:lang="en">Student</rdfs:label>
</owl:Class>

<owl:Class rdf:about="#Teacher">
<rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<owl:disjointWith rdf:resource="#Student" />
<rdfs:label xml:lang="en">Staff</rdfs:label>
</owl:Class>

<owl:DatatypeProperty rdf:about="#name">
<rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#first-name">
<rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#gender">
<rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#institution">
<rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#city-of-study">
<rdfs:domain rdf:resource="#Student" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#country-of-study">
<rdfs:domain rdf:resource="#Student" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#year-in-phd">
<rdfs:domain rdf:resource="#Student" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#topics-of-interest">
<rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="#phd-advisor">
<rdfs:domain rdf:resource="#Student" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<Student rdf:about="#dkral">
<name>Krall</name>
<first-name>Diana</first-name>
<gender>Female</gender>
<institution>Royal University of Worchester sauce</institution>
<city-of-study>Worchester sauce</city-of-study>
<country-of-study>GB</country-of-study>
<year-in-phd>1</year-in-phd>
<topics-of-interest>OWL and SKOS: Exploring the relationship between       formal and informal knowledge representation</topics-of-interest>
<phd-advisor>Dr. A. Verdura</phd-advisor>
<phd-advisor>C. Fragola</phd-advisor>
</Student>

我可以在上面运行一些 sparql 查询。

我的对齐本体是:

<rdf:RDF
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">

<owl:Ontology rdf:about="">
<rdfs:comment>Matched ontologies</rdfs:comment>
<rdfs:comment>Generated by      fr.inrialpes.exmo.align.renderer.OWLAxiomsRendererVisitor</rdfs:comment>
<rdfs:comment>method: fr.inrialpes.exmo.align.ObjectAlignment#toObject</rdfs:comment>
<owl:imports rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl"/>
<owl:imports rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl"/>
 </owl:Ontology> 
 <owl:DatatypeProperty     rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#  supervisor">
     <owl:equivalentProperty      rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.o       wl#phd-advisor"/>
       </owl:DatatypeProperty>

我的问题是我不知道对齐本体的 sparql 查询应该是什么以及什么是结构?

我使用 Apache Jena 接口,我的 sparql 查询代码是:

OntModel model = (OntModel)ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF, null );
    // Load ontology 1
    //OntModelSpec.OWL_MEM_RDFS_INF or no arguments to see the difference...
    model.read( "file:Ontologies/ontology1.owl" );
    // Query in ontology 1
    displayQueryAnswer( model, QueryFactory.read( "file:Ontologies/query.sparql" ) );
   // Execute the query and obtain results
    QueryExecution qe = QueryExecutionFactory.create( query, model );
    ResultSet results = qe.execSelect();
    // Output query results 
    ResultSetFormatter.out(System.out, results, query);
    if ( qe != null ) qe.close();
    }

我可以使用ontology1.owl上的 SPARQL 查询来获取数据

但我不知道如何编写 SPARQL 查询来从对齐本体中获取数据!谁能举个例子?

4

0 回答 0