How to extract the nodes that occur both an object and an object in a graph?

I want to get a list of nodes (vertices in a graph) that occur both in the subject and in the subject of the triple (not necessarily the same triple).

I tried to do this using the following query:

SELECT ?x
{

       ?x ?p ?o.

     {
         SELECT ?x  WHERE { ?s ?p ?x . }
     }
}

This does not give me exact results in the sense that I get multiple instances of the node instance. And when I tried DISTINCT, for some reason it gave even more instances.

On the side of the note, if I wanted to retrieve the nodes that are the OR object, how should I do this?

Sorry if there are errors in the dictionary used.

+4
source share
1 answer

Nodes that are objects and objects

-, :

select distinct ?x {
  ?s1 ?p1  ?x .
   ?x ?p2 ?o2 .
}

( )

, , -

prefix : <...anything...>

select distinct ?x {
  ?x (:|!:) ?o ; ^(:|!:) ?s .
}

(:|!:) , :, :. , ; . ( ?p, , & hellip;) ^p p, (, , ?person foaf:name ?name ?name ^foaf:name ?person . (:|!:) , ^(:|!:) . , ?p " ", ^?p " " ; , , ?x :p2 :o1 ?x :p2 :o2 ?x :p1 :o1 ; :p2 :o2 , :..

?x  (:|!:) ?o ;    # every ?x that is a subject
   ^(:|!:) ?s .    # every ?x that is an object

,

?x (:|!:) ?o ; ^(:|!:) ?s .

, .:)

,

node degree, SPARQL?. :

select ?x (count(*) as ?degree) { 
  { ?x ?p ?o } union
  { ?s ?p ?x }
}
group by ?x

, . :

select distinct ?x  { 
  { ?x ?p ?o } union
  { ?s ?p ?x }
}

, :

select distinct ?x {
  ?x (:|!:)|^(:|!:) [].
}
+7

Source: https://habr.com/ru/post/1545086/


All Articles