0

I'm trying to create a graph with all the related predicates and objects. To illustrate, I have the instance ex:First_Civil_War and now I want all predicates and objects to be shown in the graph. I have done this in the following way.

construct { 
} where { 
    ex:Fourth_Conquest_of_Gaul ?p ?o
} limit 100 

However, I want to exclude some of the predicates, for example ex:hasActor. How would I go about this, as the OPTIONAL statement does not work within a CONSTRUCT query.

2
  • why does OPTIONAL not work? You can put any SPARQL query into the WHERE part. I also don't see how OPTIONAL is used to exclude triples, that would be more the task of a FILTER Commented Jun 25, 2022 at 8:54
  • 1
    There is nothing in the template part CONSTRUCT {} so it returns the empty graph. Put in the triple patterns you want returned - but not the word OPTIONAL. You can add triple patterns with variables used in an OPTIONAL clause in the WHERE part. The triple template is skipped if a variable is unbound. Commented Jun 25, 2022 at 11:42

2 Answers 2

1
construct { 
} where { 
   ex:Fourth_Conquest_of_Gaul ?p ?o
} limit 100 

However, I want to exclude some of the predicates, for example ex:hasActor. How would I go about this, as the OPTIONAL statement does not work within a CONSTRUCT query.

As noted in the comments, you have an empty template (construct {} where...), but you're probably looking for a plain construct where { .... If you're looking to filter out certain values of ?p, you can use FILTER in the where part. E.g.:

construct where {
  ex:Fourth_Conquest_of_Gaul ?p ?o
  filter ( ?p != ex:hasActor )
} limit 100 
Sign up to request clarification or add additional context in comments.

Comments

0

As noted in the comments, you have an empty template (construct {} where...), but you're probably looking for a plain construct where { .... If you're looking to filter out certain values of ?p, you can use FILTER in the where part. E.g.:

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.