Notice: Scheduled maintenance is set for Tuesday, Sept 2nd at 1am EST. During this time, we will experience up to 20 minutes of downtime. Thank you for your patience.


Hello

TripleStore store = new TripleStore();

store.LoadFromFile(Server.MapPath("CarInstances.rdf")); -- error

rdfparseexception

{"[Line 7 Column 14] Unexpected Character (Code 49) 1 was encountered"}

this is a file <?xml version="1.0" encoding="UTF-8"?> <rdf:rdf xmlns:car="Http://klzzwxh:0000 xmlns:usr=" http:="" klzzwxh:0001="" klzzwxh:0002="" 2002="" 07="" owl#"="" klzzwxh:0003="" 1999="" 02="" 22-rdf-syntax-ns#"="" klzzwxh:0004="" 2000="" 01="" rdf-schema#"=""> <rdf:description rdf:about="car:Car1"> <rdf:type> <rdf:description rdf:about="car:Car"/> </rdf:type> <car:carno>123456</car:carno> <car:model> Mitsubishi Lancer </car:model> <car:modelyear> 2006 </car:modelyear> <car:kind> #Sedan </car:kind> <car:color> #Blue </car:color> <car:kilometer> 40000</car:kilometer> <car:price> 800000 </car:price> <car:imager> Http://www.MyWebCar/Photo/Car1.jpg </car:imager> <car:phone>011-22323433</car:phone> <car:mobile> 0944345234</car:mobile> <car:createdby rdf:resource="usr:User1"/> </rdf:description> <rdf:description rdf:about="car:Car2"> <rdf:type> <rdf:description rdf:about="car:Car"/> </rdf:type> <car:carno>3452345</car:carno> <car:model> Toyota Corola </car:model> <car:modelyear> 2007 </car:modelyear> <car:kind> #Sedan </car:kind> <car:color> #Red </car:color> <car:kilometer> 60000</car:kilometer> <car:price> 850000 </car:price> <car:imager> Http://www.MyWebCar/Photo/Car2.jpg </car:imager> <car:phone>011-26876875</car:phone> <car:mobile> 0944687634</car:mobile> <car:createdby rdf:resource="usr:User2"/> </rdf:description> </rdf:rdf>

asked 19 Feb '12, 04:38

mhdeyad's gravatar image

mhdeyad
23725
accept rate: 0%


The LoadFromFile() method on a Triple store assumes a dataset file i.e. NQuads, TriG or TriX so when you try and load a RDF graph it assumes it is a dataset and uses the wrong parser.

What you want to do instead is the following:

TripleStore store = new TripleStore();
Graph g = new Graph();
g.LoadFromFile("example.rdf");
store.Add(g);

The LoadFromFile() method on a Graph expects a graph file so will correctly recognize the format and select the correct parser.

link

answered 19 Feb '12, 15:46

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.9k1715
accept rate: 29%

edited 19 Feb '12, 15:53

1

I realise that this behaviour is obviously confusing to new users so I have raised an issue for this (CORE-186) so that future versions of the API will behave more intuitively i.e. as @mhdeyad expected

(19 Feb '12, 19:27) Rob Vesse ♦ Rob%20Vesse's gravatar image

I do not know what's causing the error since your RDF/XML code validates, but I see a number of problems in your RDF file:

  1. www.CarOntology is not a valid domain name;
  2. Http://www.CarOntology/CarSchema# starts with a capital letter and it should not;
  3. many of the literal values are starting or ending with a space (so if I'm searching for a car made in 2006, for instance, I wouldn't find any because you've put a space in the value);
  4. it is not possible to use namespace prefixes inside the rdf:about or rdf:resource attribute values (e.g., rdf:about="car:Car1" should be replaced by rdf:about="Http://www.CarOntology/CarSchema#Car1");
  5. for the properties car:Color and car:Kind, you use a '#' in the literal values but it would make more sense to simply write "Blue" rather than " #Blue ", unless your intention was to use a URI, in which case it should be <car:Color rdf:resource="#Blue"/>.

Moreover, you could be more concise for the type declaration and simply write:

<rdf:type rdf:resource="Http://www.CarOntology/CarSchema#Car"/>

instead of:

<rdf:type>
  <rdf:Description rdf:about="car:Car"/>
</rdf:type>

Remark: I do not want to edit your code to format it better because maybe it's important to keep the exact source code, but this is what it looks like if formatted nicely:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:car="Http://www.CarOntology/CarSchema#"
         xmlns:usr="Http://www.Users/UserIns#"
         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#">
  <rdf:Description rdf:about="car:Car1">
    <rdf:type>
      <rdf:Description rdf:about="car:Car"/>
    </rdf:type>
    <car:CarNo>123456</car:CarNo>
    <car:Model> Mitsubishi Lancer </car:Model>
    <car:ModelYear> 2006 </car:ModelYear>
    <car:Kind> #Sedan </car:Kind>
    <car:Color> #Blue </car:Color>
    <car:KiloMeter> 40000</car:KiloMeter>
    <car:Price> 800000 </car:Price>
    <car:Imager> Http://www.MyWebCar/Photo/Car1.jpg </car:Imager>
    <car:Phone>011-22323433</car:Phone>
    <car:Mobile> 0944345234</car:Mobile>
    <car:CreatedBy rdf:resource="usr:User1"/>
  </rdf:Description>
  <rdf:Description rdf:about="car:Car2">
    <rdf:type>
      <rdf:Description rdf:about="car:Car"/>
    </rdf:type>
    <car:CarNo>3452345</car:CarNo>
    <car:Model> Toyota Corola </car:Model>
    <car:ModelYear> 2007 </car:ModelYear>
    <car:Kind> #Sedan </car:Kind>
    <car:Color> #Red </car:Color>
    <car:KiloMeter> 60000</car:KiloMeter>
    <car:Price> 850000 </car:Price>
    <car:Imager> Http://www.MyWebCar/Photo/Car2.jpg </car:Imager>
    <car:Phone>011-26876875</car:Phone>
    <car:Mobile> 0944687634</car:Mobile>
    <car:CreatedBy rdf:resource="usr:User2"/>
  </rdf:Description>
</rdf:RDF>
link

answered 19 Feb '12, 07:07

Antoine%20Zimmermann's gravatar image

Antoine Zimm... ♦
10.2k514
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×80

Asked: 19 Feb '12, 04:38

Seen: 793 times

Last updated: 19 Feb '12, 19:27