-1

I have 2 sparql queries but they don't returns correct results (triples) First one return correct result but some triples are missed the second one returns all correct triples but not in the right format, in fact i don't want to display uri 1:

SELECT  distinct  ?s ?v ?o  WHERE {
    {        ?s2 pred:relationsubject ?s_urii .
        ?s_urii pred:name ?s . 
        ?s2 pred:relationobject ?o .
        ?s2 pred:verb ?v . 

    }

result:

1   MM  mismanage   H
2   HC  take            T
3   HC  be          D
4   HC  face            P

2:

SELECT  distinct  ?s_urii ?v ?o  WHERE {
{        ?s2 pred:relationsubject ?s_urii .
    ?s2 pred:relationobject ?o .
    ?s2 pred:verb ?v . 

}

result:

 1  http://5a0  mismanage   H
2   http://6b1  take            T
3   http://6b1  be          D
4   http://6b1  face            P
5   http://5a0  make with   G
6   http://6b1  not make    TN
7   http://6b0  have            TL

thoses URI(http://5a0,http://5b1...) corresponds to sujects (MM,HC...) in the database. Can anyone please tell me the problem? I'm using ARC triplestore so triples are stored in mysql database and i'm using php language to execute my queries. You find in this link the file which contains data enter link description here

I also tried this query but it do not give me the all records:

SELECT  distinct  ?s ?v ?o  WHERE {
    {        ?s2 pred:relationsubject ?s_urii .
        ?s_urii pred:name ?s . 
        ?s2 pred:relationobject ?o .
        ?s2 pred:verb ?v . 

    }
bibi007
  • 1
  • 2
  • 2
    It's not clear what you're asking or what results you're trying to get, and you haven't shown us the data. We don't know what triplestore you're using, or what you prefixes are. We don't have enough information to reproduce your problem. The only thing I can point out offhand is that in the first case you're getting `?s` from `?s_urii pred:name ?s`, whereas in the second you've got `?s2 pred:relationsubject ?s_urii` (with `?s_urii` instead of `?s`). Perhaps in the first case, some `?s_urii` bindings don't have `pred:name` values? – Joshua Taylor Jun 02 '14 at 01:52
  • I would like to share the .sql file which contain my data but how? and no, all ?s_urii bindings have pred:name values – bibi007 Jun 02 '14 at 11:39
  • A .sql file? SPARQL is used to query against RDF data, and that, depending on the format that it's stored in, usually has a suffix: .rdf, .owl, .nt, .n3, .ttl, etc. In any case, without seeing the data that you're querying against and knowing more about your setup, we can't really offer more help. Please use the "edit" link under the question to add the data to the question, and show us the code you're using to run the query. Are you submitting the query to a web interface? Running the query in a program? There's not enough information yet. – Joshua Taylor Jun 02 '14 at 12:07
  • ok i will edit it but how to share the .sql file. I'm using ARC triplestore so triples are stored in mysql database. – bibi007 Jun 02 '14 at 15:58
  • why not just copy and paste some of the contents into the question as a code block? – Joshua Taylor Jun 02 '14 at 16:00
  • i uploaded the file, in a hyperlink – bibi007 Jun 02 '14 at 16:03
  • There's no reason to use a service like that when things like pastebin, etc., are available. Even so, that's an SQL dump. SPARQL is a query language for RDF. That file might be generating the data that you're querying over, but if that's the case, there's some database/RDF layer that's not described in your code, and in any case, it's not the data that we can use to test queries. – Joshua Taylor Jun 02 '14 at 16:09
  • I know that sparql is a query language for RDF, this is exactly what i do, i'm storing my triples in mysql database instead of file. So what i must share to help me? the code which execute queries? – bibi007 Jun 02 '14 at 16:38
  • But you must be doing *something* that's allowing you to run SPARQL queries against data stored in a database that supports SQL. If you're translating queries by hand, you haven't shown that. If you're using some database that supports SPARQL, you haven't mentioned in the question. Think of the question in terms of "what would someone else need to do to be able to reproduce the problem?" Right now, no one reading this question can reproduce it and figure out how to fix it, because there's not enough information to reproduce it. As it stands now, a perfectly sensible response would be: – Joshua Taylor Jun 02 '14 at 16:40
  • "Your script populates a database that can be queried with SQL. You've got SPARQL queries though, and you can't run SPARQL queries against the database, because they're not SQL queries. Thus you must have fabricated your results." I don't believe that you have fabricated the results, but there's nothing in the *question* that shows how you could be getting them. – Joshua Taylor Jun 02 '14 at 16:42
  • Sir, i'm running my queries and i have got result i don't have problem about querying. all that is done by "arc". My problem is about result that i got. – bibi007 Jun 02 '14 at 17:03

1 Answers1

0

bibi, your question is not totally clear and from the look of your sparql query i judge that you absolutely new to sparql and have tried many things that lead you from ?s to ?s1 to ?s2 to ?s_urii... i'd say that were four hours of try and catch.. not wasted i'm sure you learned something ;-) (by the way the curly braces in above queries are unbalanced and cannot be run like they are above)

now, rdf (imagine rdf as being a big table with three columns, one for the subject, one for the predicate and one for the object of a triple) and the corresponding query language (sparql) are two really simple things of you know what you are doing.

  1. first run the following query and take a look at the data, so you are at least semi-familiar with the subjects, predicates and objects.

    SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 100
    

this translates to human language : show me everything where there is a triple. and bind the value in the subject column to variable ?s, the value in the predicate column to ?p and the value in the object column to variable ?o.

  1. checkout what happens, when you do :

    SELECT ?s WHERE { ?s ?p ?o } LIMIT 100
    
    SELECT ?p WHERE { ?s ?p ?o } LIMIT 100
    
    SELECT ?o WHERE { ?s ?p ?o } LIMIT 100
    
    SELECT DISTINCT ?s WHERE { ?s ?p ?o } LIMIT 100
    
    SELECT DISTINCT ?p WHERE { ?s ?p ?o } LIMIT 100
    
    SELECT DISTINCT ?o WHERE { ?s ?p ?o } LIMIT 100
    

also try

SELECT DISTINCT ?UNDEF WHERE { ?s ?p ?o } LIMIT 100 

please note that ?s ?p ?o are only variable names, you can replace them also by ?cat ?dog ?bird if you like. please also note, that sparql select queries return bindings and not triples.

if the second query contains the bindings you are after and you just want to remove ?s_urii, then just don't select it.

SELECT  distinct ?v ?o  WHERE {
?s2 pred:relationobject ?o .
?s2 pred:verb ?v . 
}
  • I'm beginner in sparql right, but i'm trying my best. In fact, the second query return the right number of records but instead of uri i want to display names just like the result of my first query. I also tried this query but it do not give me the all records: SELECT distinct ?s ?v ?o WHERE { { ?s2 pred:relationsubject ?s_urii . ?s_urii pred:name ?s . ?s2 pred:relationobject ?o . ?s2 pred:verb ?v . } – bibi007 Jun 02 '14 at 17:42
  • try `SELECT distinct ?name ?verb ?relObj WHERE { ?subject pred:relationobject ?relObj . ?subject pred:verb ?verb . OPTIONAL { ?subject pred:relationsubject ?relSubj . ?relSubj pred:name ?name . } }` apparently not all ?s2 have a relationsubject ?s_urii which has a name (note: i renamed the variables in my sample). – user3700228 Jun 02 '14 at 22:52
  • Ok i will try it and give you a feedback. Thank you – bibi007 Jun 02 '14 at 23:20
  • This query do not return any result :( – bibi007 Jun 02 '14 at 23:36