i need away to write rdf triples with Time attributes and make sparql query to get the time

StackOverflow https://stackoverflow.com/questions/16449341

Pregunta

i have triples: Fadi eat Apple. (subject = Fadi, predicate = eat, object = Apple). and i have the Time when fadi eat the Apple, its: 00:00:13 and i have the time when fadi ate the apple, its: 00:00:50

how can i write a rdf-triples file for this with times as attributes? and how can i get the startTime and endTime with sparql query request from the rdf file?

i tried to write my rdf like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dnr="http://www.dotnetrdf.org/configuration#"
         xml:base="http://www.example.org/"
    xmlns:startTime="http://example.org/startTime#"
    xmlns:endTime="http://example.org/endTime#">

<rdf:Description rdf:about="Fadi">
        <ns:be xmlns:ns="http://example.org/" xmlns:startTime="00:00:13" xmlns:endTime="00:00:16">May</ns:be>
      </rdf:Description>
</rdf:RDF>

but the c# gaves me: Invalid URI: The URI scheme is not valid.

and i tried this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dnr="http://www.dotnetrdf.org/configuration#"
         xml:base="http://www.example.org/">

<rdf:Description rdf:about="Fadi">
        <ns:be xmlns:ns="http://example.org/" xml:startTime="00:00:13" xml:endTime="00:00:16">May</ns:be>
      </rdf:Description>
</rdf:RDF>

but i can't get the times with sparql.

how can i write my rdf?!!

¿Fue útil?

Solución

You shouldn't be using xmlns to try and define attributes, xmlns is a reserved prefix in XML used for defining namespaces.

Once you have defined your own namespace you can then use it for attributes e.g.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:ns="http://yourdomain.com/namespace#"
         xml:base="http://www.example.org/">

  <rdf:Description rdf:about="Fadi" ns:startTime="00:00:13" ns:endTime="00:00:16">
    <ns:be>May</ns:be>
  </rdf:Description>
</rdf:RDF>

Here I defined a namespace in the root element like so:

xmlns:ns="http://yourdomain.com/namespace#"

Obviously you should change the namespace URI to something appropriate for you.

Then I can use the newly defined ns prefix to refer to terms in that namespace e.g.

ns:startTime="00:00:13"

Suggestion

However I still don't think this is going to give you the data you are intending to create. I would suggest that your stop trying to write RDF/XML by hand which what your questions imply you are doing.

Instead I would recommend learning a human readable serialization like Turtle since it is significantly easier to understand. Also it is much more triple centric than RDF/XML so it will help you to understand much better the RDF triples you are actually expressing and thus will make it easier for you to understand how to write SPARQL queries that actually return the data you want.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top