0

I'm a beginner in Apache Spark, SPARQL, I'm trying to make some queries on an RDF file using CIDOC-CRM ontology, I execute this SPARQL query but It never turn with a result

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 """ )

a sample from data.rdf as below

<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>

for example I would like to get the label "Mirella Serlorenzi" and all the others, respecting the conditions in the query

   <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>

I hope that you have some help, or some books to get a look, thanks in advance

Alper t. Turker
  • 34,230
  • 9
  • 83
  • 115
Yardi
  • 101
  • 8
  • Doesn't seem to be related to [tag:apache-spark]. – Alper t. Turker Jan 24 '18 at 16:35
  • I'm using it, on pyspark – Yardi Jan 24 '18 at 17:47
  • So where is your Spark code? :) May I recommend a [mcve]? For now it looks like a plain SPARQL question. – Alper t. Turker Jan 24 '18 at 17:53
  • 1
    typo in namespace declaration of your query: `http://www.ics.forth.gr/isl/CRMextCRMarchaeo.rdfs/` - there is a missing `/` after `CRMext` – UninformedUser Jan 24 '18 at 20:39
  • Thank you @AKSW in my file is as you said, it should an error when I copied it. I still get nil as a result of my query :/ – Yardi Jan 25 '18 at 19:30
  • The problem is that you misunderstand the RDF/XML serialization of your data: `` means there is an individual `http://archaeositarproject.it/st_information_source_#4104` that belongs to class `archaeo:A1_Excavation_Process_Unit` – UninformedUser Jan 25 '18 at 20:47
  • In your query you assume that `archaeo:A1_Excavation_Process_Unit` it is a property . The correct start would be `?s a archaeo:A1_Excavation_Process_Unit` or you start directly from the individual `http://archaeositarproject.it/st_information_sour‌​ce_#4104 crm:P01i_is_domain_of`?o .` – UninformedUser Jan 25 '18 at 20:49

1 Answers1

0

Thank you guys anyway, I found the way to fix up the problem,

here a query example I wanted to do:

g.parse("pyrdfLib/sitar_rdf.rdf")

g.bind(a,b): it's for binding the PREFIX:

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 .

} """ )
Yardi
  • 101
  • 8