tags:

views:

324

answers:

3

I am creating a query form and let the user to enter the keyword from the form. Then the query form will bring to the next page where I carry the variable created in the query form to the next page. The excerpt code for the new page is as folows:

//received variable
$abc1=$_POST['querykeyword'];

$querystring = '
Prefix try <http://www.semanticweb.org/ontologies/2009/5/test.owl#&gt;
SELECT ?name ?age
WHERE
  {     ?url try:has-name ${"abc1"} ?name 
        ?url try:has-age ?age }';

However, it did not give the output. Can anybody help?

A: 

There seems to be a number of syntax issues in your query. try:has-name property probably has a literal domain. So you should put your literal in quotes. There's also a . missing between the graph patterns, and some other quirks, some of which are related to stackoverflow's formatting of non-code text (fixed by reformatting the question). However, try this:

$querystring = '
  PREFIX try: <http://www.semanticweb.org/ontologies/2009/5/test.owl#&gt;
  SELECT ?name ?age {
    ?url try:has-name ?name .
    ?url try:has-age ?age .
    FILTER(?name = \"${"abc1"}\")
  }';

The PREFIX statement declares the try namespace prefix. Then there's the SELECT clause that selects two variables nameand age. Note that WHERE is optional. The two graph patterns select triples that match both patterns, and the FILTER retains only those triples that satisfy the name matching criteria. @tialaramex's solution would probably also work for you since you already know the name. I'm editing this to be slightly different solution, in case you want to use more complex filtering operations in the future.

laalto
@Prefix is a Turtle feature. This is SPARQL. It's just PREFIX in SPARQL, not @Prefix.
tialaramex
@tialaramex: Thanks again. Fixed. Will parse my queries next time :)
laalto
I tried this way, however the result shown as 'no match' in the browser. But I know it should give me the name and age in the HTML table.
+1  A: 

Both the query in the question and laalto's answer aren't valid SPARQL, but laalto is getting closer.

It seems like Ismet wants to replace the ?name variable with a fixed value. If so, the ?name variable must be removed from the SELECT and the query body, or it shouldn't parse and certainly won't return the desired results. The PHP used also has the wrong escaping for a T_VARIABLE, the PREFIX was missing a colon required by SPARQL syntax rules.

Try:

  $querystring = "
  PREFIX try: <http://www.semanticweb.org/ontologies/2009/5/test.owl#&gt;
  SELECT ?age
  WHERE {
    ?url try:has-name \"${abc1}\" .
    ?url try:has-age ?age
  }";

This should at least emit a syntactically correct SPARQL query which contains your variable.

tialaramex
@tialaramex: Thanks for noticing, revised my answer now.
laalto
I tried it but i still not give me the output.
Have you tried manually executing your desired query to check that it actually works?
tialaramex
I tried the query manualy and it works. WIll send to you the file.
tialaramex: how can i send the file to you? sorry to bother you.
You could use pastebin.com and write the resulting URLs into a comment here.Since a manual query works, I suppose the problem must be with the PHP, but I can't see how. So maybe include a snippet of PHP that doesn't work, as well as the text of the manual query that worked. Use copy-paste to avoid transcription errors.
tialaramex
A: 

An old question, but for FWIW: I'd recommend using Fresnel, it's more work initially but you'll have more flexibility and they've already worked through some of the pain points. Fresnel is an RDF presentation vocabulary for describing how to display RDF. You could use a SPARQL CONSTRUCT query to gather your data and then pass it to a Fresnel engine to generate the HTML, with a cache layer in between for performance.

Some Fresnel engine implementations, see Horus especially since you're working in PHP:

  • SIMILE's Fresnel Engine; Java, available in a Maven repository

  • Emmanuel's IsaViz (partial; fully implements FSL); Java, likely will utilize SIMILE engine

  • Freie Universität Berlin's Horus; PHP

  • OlinCollege (unknown)

Bill Barnhill