my main function says--

static void Main(string[] args) {

        Graph g = new Graph();
        FileLoader.Load(g, "\\cbcs.owl");

        TripleStore store = new TripleStore();
        store.Add(g);
        //Object results = store.ExecuteQuery("SELECT * WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }");

        Object results = store.ExecuteQuery("PREFIX pre:<http://www.cbcs.com/ontologies/cbcs.owl#>" + "SELECT ?X ?Y WHERE { ?X pre:hasInstitutes ?Y .}");
        SparqlResultSet rset = (SparqlResultSet)results;

        //Enumerating via the Results property
        foreach (SparqlResult result in rset.Results)
        {
            Console.WriteLine(result.ToString());
        }

        Console.WriteLine("hello");
        Console.ReadLine();
    }

but it doesnt display the answer if my query is simple and without answer it works but with prefix it doesnt please help

asked 31 Jan '13, 07:07

jasmine's gravatar image

jasmine
-1
accept rate: 0%

closed 31 Jan '13, 07:58

Rob%20Vesse's gravatar image

Rob Vesse ♦
14.0k1715

The question has been closed for the following reason "Duplicate of https://answers.semanticweb.com/questions/20700/problem-with-query-in-dotnetrdf" by Rob Vesse 31 Jan '13, 07:58


@jasmine: As @Rob Vesse has mentioned in your previous post regarding the same question Problem with query in dotNetRDF, you need to be more specific with your query as to what exactly do you want and what are the queries that are working?

You can also refer to the discussion made on Executing SPARQL Query on an Ontology developed by Protege 3.4.8 using dotNetRDF. That was from where I started my successful executions, all thanks to @Rob Vesse

P.S. Rather than just copying the same example, try it out with a simple query of your own that successfully runs on Protege and check out if the result is being displayed.

permanent link

answered 31 Jan '13, 07:25

George%20Abraham's gravatar image

George Abraham
25928
accept rate: 16%

edited 31 Jan '13, 07:28

@jasmine: Try this:

public partial class Form1 : Form
{
    TripleStore store = new TripleStore();

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult dresult = openFileDialog1.ShowDialog(); // Show the dialog.
        if (dresult == DialogResult.OK) // Test result.
        {
            string file = openFileDialog1.FileName;
            try
            {
                //Load in our ontology we created in protege
                store.LoadFromFile(file);
            }
            catch (IOException)
            {
            }
        }
    }

    private void btnExecuteQuery_Click(object sender, EventArgs e)
    {
        String queryString = txtEnterQuery.Text;
        Object results = store.ExecuteQuery(queryString);
        if (results is SparqlResultSet)
        {
            //Print out the Results
            SparqlResultSet rset = (SparqlResultSet)results;
            foreach (SparqlResult r in rset)
            {
                foreach (String var in r.Variables)
                {
                    if (r.HasValue(var) && r[var] != null)
                    {
                        INode n = r[var];
                        String output;
                        switch (n.NodeType)
                        {
                            case NodeType.Literal:
                                //For literals you only want the lexical value only so need to cast to
                                //literal and access the Value property
                                output = ((ILiteralNode)n).Value;
                                //Console.Write(var.ToString() + ": " + output);
                                richTxtAnswer.Text += var.ToString() + ": " + output;
                                break;
                            case NodeType.Uri:
                                Uri u = ((IUriNode)n).Uri;
                                if (!u.Fragment.Equals(String.Empty))
                                //u.Fragment is the fragment ID, the #blah part of the URI
                                {
                                    output = u.Fragment.Substring(1);
                                }
                                else
                                {
                                    output = u.AbsoluteUri;
                                }
                                richTxtAnswer.Text += var.ToString() + ": " + output;
                                break;
                            default:
                                //For any other node we just want the string form so
                                //ToString() is sufficient
                                output = n.ToString();
                                richTxtAnswer.Text += var.ToString() + ": " + output;
                                break;
                        }
                    }
                    richTxtAnswer.Text += "\n";
                }
                richTxtAnswer.Text += "\n";
            }
        }
    }

Btw here is one such simple query that I executed:

PREFIX pre: <http://www.owl-ontologies.com/LRBrain_Simple.owl#> SELECT ?name ?Characteristics ?Behaviour WHERE { ?Person pre:hasCharacteristics ?Characteristics. ?Person pre:name ?name. ?Characteristics pre:showsBehaviour ?Behaviour } ORDER BY ?name
permanent link

answered 31 Jan '13, 07:38

George%20Abraham's gravatar image

George Abraham
25928
accept rate: 16%

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

Question tags:

×1,328
×216
×80
×19

question asked: 31 Jan '13, 07:07

question was seen: 962 times

last updated: 31 Jan '13, 07:59