使用 CIDOC-CRM 使用 RDF 文件查询关于 SPARQL ontology
Query regarding SPARQL with a RDF file using CIDOC-CRM ontology
我是 Apache Spark、SPARQL 的初学者,我正在尝试使用 CIDOC-CRM 对 RDF 文件进行一些查询 ontology,我执行了这个 SPARQL 查询,但它从未返回结果
from rdflib import Graph
g = Graph()
g.parse("data.rdf")
res = g.query(
"""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX gml: <http://www.opengis.net/gml>
PREFIX archaeo: <http://www.ics.forth.gr/isl/CRMextCRMarchaeo.rdfs/>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm>
PREFIX sci: <http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX crmdig: <http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE { [ archaeo:A1_Excavation_Process_Unit [ crm:P01i_is_domain_of
[ crm:PC14_carried_out_by [ crm:P02_has_range
[ crm:E21_Person [ crm:P1_is_identified_by
[ crm:E82_Actor_Appellation
[ rdfs:label ?label ] ] ] ] ] ] ] ] }
LIMIT 20 """ )
来自 data.rdf 的样本如下
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:gml="http://www.opengis.net/gml"
xmlns:archaeo="http://www.ics.forth.gr/isl/CRMext/CRMarchaeo.rdfs/"
xmlns:crm="http://www.cidoc-crm.org/cidoc-crm/"
xmlns:sci="http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:crmdig="http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<archaeo:A1_Excavation_Process_Unit
rdf:about="http://archaeositarproject.it
/st_information_source_#4104">
<crm:P1_is_identified_by>
<crm:E41_Appellation>
<rdfs:label>ninfeo e biblioteca di via Lanza</rdfs:label>
</crm:E41_Appellation>
</crm:P1_is_identified_by>
<crm:P3_has_note xml:lang="ita">Breve nota sul rinvenimento di alcune strutture sulla carreggiata di via dello Statuto, fatta da R. A. Lanciani al momento della scoperta, sul Bollettino Comunale</crm:P3_has_note>
<crm:P01i_is_domain_of>
<crm:PC14_carried_out_by>
<crm:P02_has_range>
<crm:E40_Legal_Body rdf:about="http://archaeositarproject.it/st_person_#382_106164915">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>SSBAR</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E40_Legal_Body>
</crm:P02_has_range>
<crm:P14.1_in_the_role_of>
<crm:E55_Type>
<rdfs:label>owner</rdfs:label>
</crm:E55_Type>
</crm:P14.1_in_the_role_of>
</crm:PC14_carried_out_by>
</crm:P01i_is_domain_of>
<crm:P4_has_time-span>
<crm:E52_Time-Span>
<crm:P82b_end_of_the_end rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1884-12-30T23:00:00Z</crm:P82b_end_of_the_end>
<crm:P81b_begin_of_the_end rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1884-12-30T23:00:00Z</crm:P81b_begin_of_the_end>
<crm:P81a_end_of_the_begin rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1883-12-31T23:00:00Z</crm:P81a_end_of_the_begin>
<crm:P82a_begin_of_the_begin rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1883-12-31T23:00:00Z</crm:P82a_begin_of_the_begin>
</crm:E52_Time-Span>
</crm:P4_has_time-span>
<crm:P2_has_type>
<crm:E55_Type rdf:about="http://archaeositarproject.it/st_acquisition_methodology_#2">
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300053702"/>
</skos:broadMatch>
<rdfs:label xml:lang="eng">tranch or sample excavation</rdfs:label>
<rdfs:label xml:lang="ita">Saggio di scavo</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<crm:P70i_is_documented_in>
<crm:E31_Document rdf:about="http://archaeositarproject.it/st_information_source_document_#33319">
<crm:P104_is_subject_to>
<crm:E30_Right>
<crm:P1_is_identified_by>
<crm:E41_Appellation rdf:about="http://archaeositarproject.it/st_license_#1">
<rdfs:label>Licenza da definire</rdfs:label>
</crm:E41_Appellation>
</crm:P1_is_identified_by>
</crm:E30_Right>
</crm:P104_is_subject_to>
<crm:P2_has_type>
<crm:E55_Type rdf:about="http://archaeositarproject.it/st_information_source_document_type_#4">
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300191086"/>
</skos:broadMatch>
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300034017"/>
</skos:broadMatch>
<rdfs:label xml:lang="eng">accompanying drawing</rdfs:label>
<rdfs:label xml:lang="ita">Elaborati descrittivi</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<crm:P3_has_note>estratto del test</crm:P3_has_note>
<crm:P102_has_title>
<crm:E35_Title>
<rdfs:label xml:lang="ita">relazione</rdfs:label>
</crm:E35_Title>
</crm:P102_has_title>
</crm:E31_Document>
</crm:P70i_is_documented_in>
<crm:P48_has_preferred_identifier>
<crm:E42_Identifier>
<crm:P2_has_type>
<crm:E55_Type>
<rdfs:label>internal code</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<rdfs:label>5518</rdfs:label>
</crm:E42_Identifier>
</crm:P48_has_preferred_identifier>
<crm:P1_is_identified_by>
<crm:E42_Identifier>
<crm:P2_has_type>
<crm:E55_Type>
<rdfs:label>internal identifier</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<rdfs:label>4104_2</rdfs:label>
</crm:E42_Identifier>
</crm:P1_is_identified_by>
<crm:P7_took_place_at>
<crm:E53_Place>
<crm:P1_is_identified_by>
<crm:E44_Place_Appellation>
<rdfs:label>Rione XV Esquilino</rdfs:label>
</crm:E44_Place_Appellation>
</crm:P1_is_identified_by>
</crm:E53_Place>
</crm:P7_took_place_at>
<crm:P01i_is_domain_of>
<crm:PC14_carried_out_by>
<crm:P02_has_range>
<crm:E21_Person rdf:about="http://archaeositarproject.it/st_person_#12_1788137750">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>Mirella Serlorenzi</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E21_Person>
</crm:P02_has_range>
<crm:P14.1_in_the_role_of>
<crm:E55_Type>
<rdfs:label>liable officier</rdfs:label>
</crm:E55_Type>
</crm:P14.1_in_the_role_of>
</crm:PC14_carried_out_by>
</crm:P01i_is_domain_of>
</archaeo:A1_Excavation_Process_Unit>
</rdf:RDF>
例如,我想获取标签 "Mirella Serlorenzi" 和所有其他标签,并遵守查询中的条件
<crm:P02_has_range>
<crm:E21_Person rdf:about="http://archaeositarproject.it/st_person_#12_1788137750">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>Mirella Serlorenzi</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E21_Person>
</crm:P02_has_range>
希望对你有所帮助,或者有书看看,先谢谢了
谢谢大家,我找到了解决问题的方法,
这是我想做的查询示例:
g.parse("pyrdfLib/sitar_rdf.rdf")
g.bind(a,b): 绑定前缀:
g.bind("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#")
g.bind("gml","http://www.opengis.net/gml")
g.bind("archaeo","http://www.ics.forth.gr/isl/CRMext/CRMarchaeo.rdfs/")
g.bind("crm","http://www.cidoc-crm.org/cidoc-crm/")
g.bind("sci","http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs/")
g.bind("skos","http://www.w3.org/2004/02/skos/core#")
g.bind("crmdig","http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/")
g.bind("rdfs","http://www.w3.org/2000/01/rdf-schema#")
res = g.query("""
SELECT ?arc1 ?mMade
WHERE {
?s rdf:type sci:S22_Segment_of_Matter .
?s crm:P140i_was_attributed_by ?arc1 .
?arc1 rdf:type archaeo:A1_Excavation_Process_Unit .
?s sci:O22_partly_or_completely_contains ?archaeo .
?archaeo rdf:type archaeo:A8_Stratigraphic_Unit .
?archaeo archaeo:AP15_is_or_contains_remains_of ?mMade .
} """ )
我是 Apache Spark、SPARQL 的初学者,我正在尝试使用 CIDOC-CRM 对 RDF 文件进行一些查询 ontology,我执行了这个 SPARQL 查询,但它从未返回结果
from rdflib import Graph
g = Graph()
g.parse("data.rdf")
res = g.query(
"""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX gml: <http://www.opengis.net/gml>
PREFIX archaeo: <http://www.ics.forth.gr/isl/CRMextCRMarchaeo.rdfs/>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm>
PREFIX sci: <http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX crmdig: <http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE { [ archaeo:A1_Excavation_Process_Unit [ crm:P01i_is_domain_of
[ crm:PC14_carried_out_by [ crm:P02_has_range
[ crm:E21_Person [ crm:P1_is_identified_by
[ crm:E82_Actor_Appellation
[ rdfs:label ?label ] ] ] ] ] ] ] ] }
LIMIT 20 """ )
来自 data.rdf 的样本如下
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:gml="http://www.opengis.net/gml"
xmlns:archaeo="http://www.ics.forth.gr/isl/CRMext/CRMarchaeo.rdfs/"
xmlns:crm="http://www.cidoc-crm.org/cidoc-crm/"
xmlns:sci="http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:crmdig="http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<archaeo:A1_Excavation_Process_Unit
rdf:about="http://archaeositarproject.it
/st_information_source_#4104">
<crm:P1_is_identified_by>
<crm:E41_Appellation>
<rdfs:label>ninfeo e biblioteca di via Lanza</rdfs:label>
</crm:E41_Appellation>
</crm:P1_is_identified_by>
<crm:P3_has_note xml:lang="ita">Breve nota sul rinvenimento di alcune strutture sulla carreggiata di via dello Statuto, fatta da R. A. Lanciani al momento della scoperta, sul Bollettino Comunale</crm:P3_has_note>
<crm:P01i_is_domain_of>
<crm:PC14_carried_out_by>
<crm:P02_has_range>
<crm:E40_Legal_Body rdf:about="http://archaeositarproject.it/st_person_#382_106164915">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>SSBAR</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E40_Legal_Body>
</crm:P02_has_range>
<crm:P14.1_in_the_role_of>
<crm:E55_Type>
<rdfs:label>owner</rdfs:label>
</crm:E55_Type>
</crm:P14.1_in_the_role_of>
</crm:PC14_carried_out_by>
</crm:P01i_is_domain_of>
<crm:P4_has_time-span>
<crm:E52_Time-Span>
<crm:P82b_end_of_the_end rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1884-12-30T23:00:00Z</crm:P82b_end_of_the_end>
<crm:P81b_begin_of_the_end rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1884-12-30T23:00:00Z</crm:P81b_begin_of_the_end>
<crm:P81a_end_of_the_begin rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1883-12-31T23:00:00Z</crm:P81a_end_of_the_begin>
<crm:P82a_begin_of_the_begin rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>1883-12-31T23:00:00Z</crm:P82a_begin_of_the_begin>
</crm:E52_Time-Span>
</crm:P4_has_time-span>
<crm:P2_has_type>
<crm:E55_Type rdf:about="http://archaeositarproject.it/st_acquisition_methodology_#2">
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300053702"/>
</skos:broadMatch>
<rdfs:label xml:lang="eng">tranch or sample excavation</rdfs:label>
<rdfs:label xml:lang="ita">Saggio di scavo</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<crm:P70i_is_documented_in>
<crm:E31_Document rdf:about="http://archaeositarproject.it/st_information_source_document_#33319">
<crm:P104_is_subject_to>
<crm:E30_Right>
<crm:P1_is_identified_by>
<crm:E41_Appellation rdf:about="http://archaeositarproject.it/st_license_#1">
<rdfs:label>Licenza da definire</rdfs:label>
</crm:E41_Appellation>
</crm:P1_is_identified_by>
</crm:E30_Right>
</crm:P104_is_subject_to>
<crm:P2_has_type>
<crm:E55_Type rdf:about="http://archaeositarproject.it/st_information_source_document_type_#4">
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300191086"/>
</skos:broadMatch>
<skos:broadMatch>
<skos:Concept rdf:about="http://vocab.getty.edu/aat/300034017"/>
</skos:broadMatch>
<rdfs:label xml:lang="eng">accompanying drawing</rdfs:label>
<rdfs:label xml:lang="ita">Elaborati descrittivi</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<crm:P3_has_note>estratto del test</crm:P3_has_note>
<crm:P102_has_title>
<crm:E35_Title>
<rdfs:label xml:lang="ita">relazione</rdfs:label>
</crm:E35_Title>
</crm:P102_has_title>
</crm:E31_Document>
</crm:P70i_is_documented_in>
<crm:P48_has_preferred_identifier>
<crm:E42_Identifier>
<crm:P2_has_type>
<crm:E55_Type>
<rdfs:label>internal code</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<rdfs:label>5518</rdfs:label>
</crm:E42_Identifier>
</crm:P48_has_preferred_identifier>
<crm:P1_is_identified_by>
<crm:E42_Identifier>
<crm:P2_has_type>
<crm:E55_Type>
<rdfs:label>internal identifier</rdfs:label>
</crm:E55_Type>
</crm:P2_has_type>
<rdfs:label>4104_2</rdfs:label>
</crm:E42_Identifier>
</crm:P1_is_identified_by>
<crm:P7_took_place_at>
<crm:E53_Place>
<crm:P1_is_identified_by>
<crm:E44_Place_Appellation>
<rdfs:label>Rione XV Esquilino</rdfs:label>
</crm:E44_Place_Appellation>
</crm:P1_is_identified_by>
</crm:E53_Place>
</crm:P7_took_place_at>
<crm:P01i_is_domain_of>
<crm:PC14_carried_out_by>
<crm:P02_has_range>
<crm:E21_Person rdf:about="http://archaeositarproject.it/st_person_#12_1788137750">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>Mirella Serlorenzi</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E21_Person>
</crm:P02_has_range>
<crm:P14.1_in_the_role_of>
<crm:E55_Type>
<rdfs:label>liable officier</rdfs:label>
</crm:E55_Type>
</crm:P14.1_in_the_role_of>
</crm:PC14_carried_out_by>
</crm:P01i_is_domain_of>
</archaeo:A1_Excavation_Process_Unit>
</rdf:RDF>
例如,我想获取标签 "Mirella Serlorenzi" 和所有其他标签,并遵守查询中的条件
<crm:P02_has_range>
<crm:E21_Person rdf:about="http://archaeositarproject.it/st_person_#12_1788137750">
<crm:P1_is_identified_by>
<crm:E82_Actor_Appellation>
<rdfs:label>Mirella Serlorenzi</rdfs:label>
</crm:E82_Actor_Appellation>
</crm:P1_is_identified_by>
</crm:E21_Person>
</crm:P02_has_range>
希望对你有所帮助,或者有书看看,先谢谢了
谢谢大家,我找到了解决问题的方法,
这是我想做的查询示例:
g.parse("pyrdfLib/sitar_rdf.rdf")
g.bind(a,b): 绑定前缀:
g.bind("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#")
g.bind("gml","http://www.opengis.net/gml")
g.bind("archaeo","http://www.ics.forth.gr/isl/CRMext/CRMarchaeo.rdfs/")
g.bind("crm","http://www.cidoc-crm.org/cidoc-crm/")
g.bind("sci","http://www.ics.forth.gr/isl/CRMext/CRMsci.rdfs/")
g.bind("skos","http://www.w3.org/2004/02/skos/core#")
g.bind("crmdig","http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/")
g.bind("rdfs","http://www.w3.org/2000/01/rdf-schema#")
res = g.query("""
SELECT ?arc1 ?mMade
WHERE {
?s rdf:type sci:S22_Segment_of_Matter .
?s crm:P140i_was_attributed_by ?arc1 .
?arc1 rdf:type archaeo:A1_Excavation_Process_Unit .
?s sci:O22_partly_or_completely_contains ?archaeo .
?archaeo rdf:type archaeo:A8_Stratigraphic_Unit .
?archaeo archaeo:AP15_is_or_contains_remains_of ?mMade .
} """ )