-1

I am having a hard time understanding how to fetch data with SPARQL. I looked at several tutorials but still have a few questions

1) How can we determine the headers in the dataset. Say there's a dataset A, and I want to extract the names and locations of people in that dataset. How can I determine the header in which the names is stored?

2) How could I extract a sub-graph containing statements about entities within 2 hops from Donald Trump A code example or web link would be very helpful.

Mark Miller
  • 3,011
  • 1
  • 14
  • 34
Chaitanya Patil
  • 183
  • 2
  • 16
  • 1) There are no "headers" in RDF. I don't know what you mean by this. RDF is simply made of triples. Nothing more, nothing less. – UninformedUser Feb 20 '19 at 20:49
  • 2) I told you to read about SPARQL `CONSTRUCT` query. So why now another question which in fact is the same as your previous question? That's against the rules of StackOverflow. – UninformedUser Feb 20 '19 at 20:50
  • 1
    I'm voting to close this question as off-topic because it's the same question as asked the day before, see https://stackoverflow.com/questions/54774104/extract-graph-from-dbpedia-by-number-of-hops-direction – UninformedUser Feb 21 '19 at 06:33
  • It is not the same question, I have posted the quetion after watching all Tutorials and when I didnt find answer, I requested for additional Tutorials or materials from where I can study. – Chaitanya Patil Feb 22 '19 at 04:38
  • And for *no headers in rdf* I meant Ex:consider triple Trump_ President_US: Here Trump is name: President is Post and US is country.. By header I meant Name, Post, Country – Chaitanya Patil Feb 22 '19 at 04:40
  • Just because you did some research doesn't change the question. It is still the same ... I told you to read about SPARQL `CONSTRUCT` queries, which in fact returns RDF triples. The rest is trivial. – UninformedUser Feb 22 '19 at 06:55
  • Here is the start, return all direct outgoing triples: `CONSTRUCT { ?p ?o} WHERE { ?p ?o }` - the rest is done analogous, attach more triple patterns if you need more data from the deeper graph and switch the direction if you also need incoming triples. No black magic, you see. – UninformedUser Feb 22 '19 at 06:58
  • Possible duplicate of [Extract Graph from DBpedia, by number of HOPS, Direction](https://stackoverflow.com/questions/54774104/extract-graph-from-dbpedia-by-number-of-hops-direction) – TallTed Feb 22 '19 at 17:17
  • @AKSW Thank You so much! It would be really great if you could suggest some tutorial/Materials for me to study completely. I explored lot of options and I feel that no tutorials have on Construct querry. Could you please help me with resources? ( which has tutorials on switching direction of triples, taking hops etc) I want to study in depth! – Chaitanya Patil Feb 22 '19 at 17:37
  • there is not really a tutorial on using `CONSTRUCT` queries, that's true. It's more like understanding the SPARQL pattern matching on an RDF graph in general. You could start by taking a subgraph of the RDF dataset, e.g. some triples around the dbpedia_Donald_Trump node, and then mapping this to triple patterns, i.e. all nodes that you don't want to be specific, replace by a variable. Once you're done, you could start with pruning, i.e. you'll clearly have redundant triple patterns. Sorry, I can't explain it better, nor do I know a good tutorial. Other people here know better for sure. – UninformedUser Feb 23 '19 at 14:41

1 Answers1

0
  1. RDF doesn't have headers. RDF has Triples which are comprised of Subjects/Entities, Predicates/Attributes, and Objects/Values. Sometimes these triples are collected into Contexts (typically, Named Graphs), which may then be serialized as Quads. To learn what predicates are in a dataset, you might execute a SPARQL query like --

    SELECT DISTINCT ?predicate
    WHERE { ?subject ?predicate ?object }
    ORDER BY ?predicate
    LIMIT 100
    
  2. What kind of hops do you want from http://dbpedia.org/resource/Donald_Trump? Probably, if you look at http://dbpedia.org/page/Donald_Trump, you will find a suitable predicate, which you might then use in a Property Path query like --

    SELECT DISTINCT ?subject ?object
    WHERE
      {
        { OPTIONAL { dbr:Donald_Trump dbo:relation/dbo:relation? ?object } }
        UNION
        { OPTIONAL { ?subject dbo:relation/dbo:relation? dbr:Donald_Trump } }
      }
    ORDER BY ?subject ?object
    LIMIT 100
    
TallTed
  • 9,069
  • 2
  • 22
  • 37
  • As far as I understand, also based in his previous question, he wants to extract a subgraph with a given URI as some kind of pivot node. And the query should also be aware of multiple hops as well as incoming and outgoing edges. So I'd assume to use a `CONSTRUCT` query and then just graph pattern like `WHERE { ?p ?o . OPTIONAL {?o ?p1 ?o1 # possibly pattern for incoming edges of outgoing edges} ... # here pattern for incoming edges ... }` - I already told him to read about this in the specs. I also told him that this subgraph can get pretty large if you want incoming edges of hops > 1 – UninformedUser Feb 21 '19 at 03:55