2 Replies Latest reply on May 16, 2008 7:36 AM by madhan2

    Help me to write SPARQL query

    madhan2
      Hi specialist,

      Can anybody guide me to write SPARQL query in java beacoz iam new to semantic technologies iam trying with family example.

      thanx
      Madhan.
        • 1. Re: Help me to write SPARQL query
          alwu-Oracle
          Here comes a simple example to get you started. You need to customize of course.

          GraphOracleSem graph = new GraphOracleSem( oracle, modelName);
          ModelOracleSem model = new ModelOracleSem(graph);

          Node sub = Node.createURI("http://test.com/employee123");
          Node pre = Node.createURI("http://xmlns.com/foaf/0.1/firstName");
          Node obj = Node.createLiteral("Julie");

          graph.add(Triple.create(sub, pre, obj));

          String queryString =
          " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
          "SELECT ?person WHERE { ?person foaf:firstName \"Julie\" . } ";

          QueryExecution qexec = QueryExecutionFactory.create(
          QueryFactory.create(queryString), model);

          try {
          ResultSet results = qexec.execSelect();
          while (results.hasNext()) {
          QuerySolution soln = results.nextSolution();
          psOut.println("runQuery: soln " + soln);
          }
          }
          finally {
          if (qexec != null)
          qexec.close();
          }
          • 2. Re: Help me to write SPARQL query
            madhan2
            thank you,

            i wil follow the example