从外部 SPARQL 端点填充 OWL ontology
Populating an OWL ontology from external SPARQL endpoints
我想 link 使用 sparql 端点的两个不同的数据集(假设 http://dbpedia.org/sparql and http://pubmed.bio2rdf.org/sparql )我将从头开始创建一个 OWL ontology,然后用这两个不同的数据集填充此 ontology。
我不熟悉语义网和 linked 数据概念。如果你们给我一些 examples/ideas 关于要开始这件事吗?
您想使用 SPARQL 一次进行两个本体查询吗?如果那么这很容易做到。获取两个本体(.OWL 文件)并使用 SPARQL(jena-fuseki 服务器)查询它,获取两个 OWL 文件的前缀。
能否请您详细说明问题?您想要端点处的 OWL 文件或 SPARQL 查询示例。
SPARQL 技巧在网上不容易找到。使用下面的示例,您可以填充 ontology。我在回答我自己的问题,感觉有点寂寞。
我使用了项目 gutenberg 端点,而不是使用 pubmed sparql 端点。首先,我使用 Protegé 创建了一个 ontology。这非常简单明了。 Followinh 是 DBPedia 和 Project Gutenberg 上卡夫卡和吐温作品元数据的示例查询。
PREFIX gb: <yourOntologyGoesHere.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
CONSTRUCT {
?book rdf:type gb:Book .
?book gb:titled_as ?name.
gb:Title rdf:type ?name.
?book gb:written_by ?author.
?author rdf:type gb:Author.
?book gb:author_name ?authorName.
gb:Author rdf:type ?authorName.
gb:AuthorName rdf:type ?authorName.
?book gb:released ?firstPublished.
?firstPublished rdf:type gb:PublishDate.
?book gb:writtenInCountry ?country .
?country rdf:type gb:Country.
?book gb:writtenIn ?lang .
?lang rdf:type gb:Language.
?book gb:summary ?abstract.
gb:Absratct rdf:type ?abstract.
?book gb:identified_with ?isbn .
gb:ISBN rdf:type ?isbn.
?book gb:publish_tpe ?mediaType .
?mediaType rdf:type gb:Media .
?book gb:has_pagenumber ?pages.
gb:Pages rdf:type ?pages.
?book gb:genre ?genre
}WHERE{?book rdf:type dbpedia-owl:Book .
?book foaf:name ?name.
OPTIONAL {?book dbpedia-owl:author ?author}
OPTIONAL {?author dbpprop:name ?authorName}
OPTIONAL {?book dbpedia-owl:releaseDate ?firstPublished}
OPTIONAL {?book dbpedia-owl:country ?country}
OPTIONAL {?book dbpedia-owl:language ?lang}
OPTIONAL {?book dbpedia-owl:abstract ?abstract}
OPTIONAL {?book dbpedia-owl:isbn ?isbn}
OPTIONAL {?book dbpedia-owl:numberOfPages ?pages}
OPTIONAL {?book dbpedia-owl:mediaType ?mediaType}
OPTIONAL {?book dbpprop:genre ?genre}
FILTER ( regex(str(?author), "Franz_Kafka") || regex(str(?author), "Mark_Twain") )
FILTER (LANG(?abstract)="en")
}
DBPedia
PREFIX gb: <yourOntologyGoesHere.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX dc: <http://purl.org/dc/terms/>
prefix owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
CONSTRUCT {
?book rdf:type gb:Book .
?book gb:title ?bookTitle .
?book gb:written_by ?author.
?author rdf:type gb:Author.
?book gb:addedToGutenberg ?addedToCatalog.
?addedToCatalog rdf:type gb:AddedToGutenberg.
?book1 rdf:type gb:Book .
?book1 gb:title ?bookTitle1 .
?book1 gb:written_by ?author1.
?author1 rdf:type gb:Author.
?author owl:sameAs <http://dbpedia.org/resource/Franz_Kafka> .
?author1 owl:sameAs <http://dbpedia.org/resource/Mark_Twain> .
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3176> owl:sameAs <http://dbpedia.org/resource/The_Innocents_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3177> owl:sameAs <http://dbpedia.org/resource/Roughing_It>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext245> owl:sameAs <http://dbpedia.org/resource/Life_on_the_Mississippi>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext9009> owl:sameAs <http://dbpedia.org/resource/Life_on_the_Mississippi>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext1086> owl:sameAs <http://dbpedia.org/resource/A_Horse's_Tale>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext119> owl:sameAs <http://dbpedia.org/resource/A_Tramp_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3174> owl:sameAs <http://dbpedia.org/resource/A_Dog's_Tale>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3186> owl:sameAs <http://dbpedia.org/resource/The_Mysterious_Stranger>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3190> owl:sameAs <http://dbpedia.org/resource/1610_(Mark_Twain)>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3251> owl:sameAs <http://dbpedia.org/resource/The_Man_That_Corrupted_Hadleyburg>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext91> owl:sameAs <http://dbpedia.org/resource/Tom_Sawyer_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext93> owl:sameAs <http://dbpedia.org/resource/Tom_Sawyer,_Detective>.
<http://dbpedia.org/resource/The_Metamorphosis> owl:sameAs <http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext5200> .
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext7849> owl:sameAs <http://dbpedia.org/resource/The_Trial>.
?book1 gb:addedToGutenberg ?addedToCatalog1.
?addedToCatalog1 rdf:type gb:AddedToGutenberg
}
WHERE {
?author foaf:name "Kafka, Franz, 1883-1924".
?author1 foaf:name "Twain, Mark, 1835-1910".
?book dc:creator ?author;
dc:title ?bookTitle;
dc:language ?bookLanguage;
dcterms:created ?addedToCatalog.
?book1 dc:creator ?author1;
dc:title ?bookTitle1;
dc:language ?bookLanguage1;
dcterms:created ?addedToCatalog1}
这两个查询将填充您创建的 ontology。然后就可以查询你新建的ontology.
使用 SPARQL SERVICE,您可以执行以下操作:
CONSTRUCT {
<dbpedia-value1> a <your-class1> .
<dbpedia-value1> ?p1 ?o1 .
<pubmed-value2> a <your-class2> . #or perhaps also <your-class1>
<pubmed-value2> ?p2 ?o2 .
}
WHERE {
SERVICE <http://dbpedia.org/sparql> {
<dbpedia-value1> a <dbp-class1> .
<dbpedia-value1> ?p1 ?o1 .
}
SERVICE <http://pubmed.bio2rdf.org/sparql> {
<pubmed-value2> a <pubmed-class1> .
<pubmed-value2> ?p2 ?o2 .
}
}
这将从每个端点的 class 获取一组实例,并将它们映射到您的 ontology。对端点的查询可以任意复杂(SPARQL IN 在这里可能很有用),但一般技术是查询该数据并使用 CONSTRUCT 将这些值映射到 ontology 中的三元组,然后保存构造的三元组. (或直接将数据插入图表。)
您还可以使用此模式在源和您的 ontology 之间映射属性。在这种情况下,在 WHERE 子句
中指定特定的 属性
<pubmed-value2> <pubmed-prop1> ?prop1value .
...然后在 CONSTRUCT 查询中转换它们:
<pubmed-value2> <your-prop1> ?prop1value .
我想 link 使用 sparql 端点的两个不同的数据集(假设 http://dbpedia.org/sparql and http://pubmed.bio2rdf.org/sparql )我将从头开始创建一个 OWL ontology,然后用这两个不同的数据集填充此 ontology。
我不熟悉语义网和 linked 数据概念。如果你们给我一些 examples/ideas 关于要开始这件事吗?
您想使用 SPARQL 一次进行两个本体查询吗?如果那么这很容易做到。获取两个本体(.OWL 文件)并使用 SPARQL(jena-fuseki 服务器)查询它,获取两个 OWL 文件的前缀。
能否请您详细说明问题?您想要端点处的 OWL 文件或 SPARQL 查询示例。
SPARQL 技巧在网上不容易找到。使用下面的示例,您可以填充 ontology。我在回答我自己的问题,感觉有点寂寞。
我使用了项目 gutenberg 端点,而不是使用 pubmed sparql 端点。首先,我使用 Protegé 创建了一个 ontology。这非常简单明了。 Followinh 是 DBPedia 和 Project Gutenberg 上卡夫卡和吐温作品元数据的示例查询。
PREFIX gb: <yourOntologyGoesHere.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
CONSTRUCT {
?book rdf:type gb:Book .
?book gb:titled_as ?name.
gb:Title rdf:type ?name.
?book gb:written_by ?author.
?author rdf:type gb:Author.
?book gb:author_name ?authorName.
gb:Author rdf:type ?authorName.
gb:AuthorName rdf:type ?authorName.
?book gb:released ?firstPublished.
?firstPublished rdf:type gb:PublishDate.
?book gb:writtenInCountry ?country .
?country rdf:type gb:Country.
?book gb:writtenIn ?lang .
?lang rdf:type gb:Language.
?book gb:summary ?abstract.
gb:Absratct rdf:type ?abstract.
?book gb:identified_with ?isbn .
gb:ISBN rdf:type ?isbn.
?book gb:publish_tpe ?mediaType .
?mediaType rdf:type gb:Media .
?book gb:has_pagenumber ?pages.
gb:Pages rdf:type ?pages.
?book gb:genre ?genre
}WHERE{?book rdf:type dbpedia-owl:Book .
?book foaf:name ?name.
OPTIONAL {?book dbpedia-owl:author ?author}
OPTIONAL {?author dbpprop:name ?authorName}
OPTIONAL {?book dbpedia-owl:releaseDate ?firstPublished}
OPTIONAL {?book dbpedia-owl:country ?country}
OPTIONAL {?book dbpedia-owl:language ?lang}
OPTIONAL {?book dbpedia-owl:abstract ?abstract}
OPTIONAL {?book dbpedia-owl:isbn ?isbn}
OPTIONAL {?book dbpedia-owl:numberOfPages ?pages}
OPTIONAL {?book dbpedia-owl:mediaType ?mediaType}
OPTIONAL {?book dbpprop:genre ?genre}
FILTER ( regex(str(?author), "Franz_Kafka") || regex(str(?author), "Mark_Twain") )
FILTER (LANG(?abstract)="en")
}
DBPedia
PREFIX gb: <yourOntologyGoesHere.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX dc: <http://purl.org/dc/terms/>
prefix owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
CONSTRUCT {
?book rdf:type gb:Book .
?book gb:title ?bookTitle .
?book gb:written_by ?author.
?author rdf:type gb:Author.
?book gb:addedToGutenberg ?addedToCatalog.
?addedToCatalog rdf:type gb:AddedToGutenberg.
?book1 rdf:type gb:Book .
?book1 gb:title ?bookTitle1 .
?book1 gb:written_by ?author1.
?author1 rdf:type gb:Author.
?author owl:sameAs <http://dbpedia.org/resource/Franz_Kafka> .
?author1 owl:sameAs <http://dbpedia.org/resource/Mark_Twain> .
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3176> owl:sameAs <http://dbpedia.org/resource/The_Innocents_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3177> owl:sameAs <http://dbpedia.org/resource/Roughing_It>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext245> owl:sameAs <http://dbpedia.org/resource/Life_on_the_Mississippi>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext9009> owl:sameAs <http://dbpedia.org/resource/Life_on_the_Mississippi>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext1086> owl:sameAs <http://dbpedia.org/resource/A_Horse's_Tale>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext119> owl:sameAs <http://dbpedia.org/resource/A_Tramp_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3174> owl:sameAs <http://dbpedia.org/resource/A_Dog's_Tale>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3186> owl:sameAs <http://dbpedia.org/resource/The_Mysterious_Stranger>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3190> owl:sameAs <http://dbpedia.org/resource/1610_(Mark_Twain)>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext3251> owl:sameAs <http://dbpedia.org/resource/The_Man_That_Corrupted_Hadleyburg>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext91> owl:sameAs <http://dbpedia.org/resource/Tom_Sawyer_Abroad>.
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext93> owl:sameAs <http://dbpedia.org/resource/Tom_Sawyer,_Detective>.
<http://dbpedia.org/resource/The_Metamorphosis> owl:sameAs <http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext5200> .
<http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/etext7849> owl:sameAs <http://dbpedia.org/resource/The_Trial>.
?book1 gb:addedToGutenberg ?addedToCatalog1.
?addedToCatalog1 rdf:type gb:AddedToGutenberg
}
WHERE {
?author foaf:name "Kafka, Franz, 1883-1924".
?author1 foaf:name "Twain, Mark, 1835-1910".
?book dc:creator ?author;
dc:title ?bookTitle;
dc:language ?bookLanguage;
dcterms:created ?addedToCatalog.
?book1 dc:creator ?author1;
dc:title ?bookTitle1;
dc:language ?bookLanguage1;
dcterms:created ?addedToCatalog1}
这两个查询将填充您创建的 ontology。然后就可以查询你新建的ontology.
使用 SPARQL SERVICE,您可以执行以下操作:
CONSTRUCT {
<dbpedia-value1> a <your-class1> .
<dbpedia-value1> ?p1 ?o1 .
<pubmed-value2> a <your-class2> . #or perhaps also <your-class1>
<pubmed-value2> ?p2 ?o2 .
}
WHERE {
SERVICE <http://dbpedia.org/sparql> {
<dbpedia-value1> a <dbp-class1> .
<dbpedia-value1> ?p1 ?o1 .
}
SERVICE <http://pubmed.bio2rdf.org/sparql> {
<pubmed-value2> a <pubmed-class1> .
<pubmed-value2> ?p2 ?o2 .
}
}
这将从每个端点的 class 获取一组实例,并将它们映射到您的 ontology。对端点的查询可以任意复杂(SPARQL IN 在这里可能很有用),但一般技术是查询该数据并使用 CONSTRUCT 将这些值映射到 ontology 中的三元组,然后保存构造的三元组. (或直接将数据插入图表。)
您还可以使用此模式在源和您的 ontology 之间映射属性。在这种情况下,在 WHERE 子句
中指定特定的 属性<pubmed-value2> <pubmed-prop1> ?prop1value .
...然后在 CONSTRUCT 查询中转换它们:
<pubmed-value2> <your-prop1> ?prop1value .