Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have rdf file

XML
<?xml version='1.0' encoding='UTF-8'?>

<rdf:RDF
  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
  xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'
   >

  <rdf:Description rdf:about="http://somewhere/JohnSmith/">
    <vCard:FN>John Smith</vCard:FN>
    <vCard:N rdf:parseType="Resource">
    <vCard:Family>Smith</vCard:Family>
    <vCard:Given>John</vCard:Given>
    </vCard:N>
  </rdf:Description>

  <rdf:Description rdf:about="http://somewhere/RebeccaSmith/">
    <vCard:FN>Becky Smith</vCard:FN>
    <vCard:N rdf:parseType="Resource">
    <vCard:Family>Smith</vCard:Family>
    <vCard:Given>Rebecca</vCard:Given>
    </vCard:N>
  </rdf:Description>

  <rdf:Description rdf:about="http://somewhere/SarahJones/">
    <vCard:FN>Sarah Jones</vCard:FN>
    <vCard:N rdf:parseType="Resource">
    <vCard:Family>Jones</vCard:Family>
    <vCard:Given>Sarah</vCard:Given>
    </vCard:N>
  </rdf:Description>

  <rdf:Description rdf:about="http://somewhere/MattJones/">
    <vCard:FN>Matt Jones</vCard:FN>
    <vCard:N
    vCard:Family="Jones"
    vCard:Given="Matthew"/>
  </rdf:Description>

</rdf:RDF>



query with c# and dotNetRDF. it doesnt work. Why? emty result

using System;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;

public class InMemoryTripleStoreExample
{
    public static void Main(String[] args)
    {
        IGraph g = new Graph();

        //Load some data into your Graph using the LoadFromFile() extension method
        g.LoadFromFile("1");

        //Use the extension method ExecuteQuery() to make the query against the Graph
        try
        {




            String q = @"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>

SELECT * WHERE
 { 
   ?a rdf:type vCard:FN .
 }
 LIMIT 100";
            Object results = g.ExecuteQuery(q);

            if (results is SparqlResultSet)
            {
                //SELECT/ASK queries give a SparqlResultSet
                SparqlResultSet rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    //Do whatever you want with each Result
                }
            }
            else if (results is IGraph)
            {
                //CONSTRUCT/DESCRIBE queries give a IGraph
                IGraph resGraph = (IGraph)results;
                foreach (Triple t in resGraph.Triples)
                {
                    //Do whatever you want with each Triple
                }
            }
            else
            {
                //If you don't get a SparqlResutlSet or IGraph something went wrong 
                //but didn't throw an exception so you should handle it here
                Console.WriteLine("ERROR");
            }
        }
        catch (VDS.RDF.Query.RdfQueryException queryEx)
        {
            //There was an error executing the query so handle it here
            Console.WriteLine(queryEx.Message);
        }
    }
}
Posted
Comments
Sunasara Imdadhusen 25-Jun-13 7:15am    
Are you getting any error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900