Filter with Path Query

i want to get path that only with :renderBlock

PATHS START ?s = :Page  END ?o VIA {
    ?s ?p ?o .
}

but there's no result in response

PATHS START ?s = :Page  END ?o VIA {
    ?s ?p ?o .
    FILTER (?p IN (:renderBlock))
}

.ttl file

@prefix : <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> .

<http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> rdf:type owl:Ontology .

#################################################################
#    Annotation properties
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderBlock
:renderBlock rdf:type owl:AnnotationProperty .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderTemplate
:renderTemplate rdf:type owl:AnnotationProperty .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block1
:Block1 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block2
:Block2 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Page
:Page rdf:type owl:Class ;
      :renderTemplate [ :renderBlock :Block1 ,
                                     :Block2
                      ] .


#################################################################
#    Individuals
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#awesome
:awesome rdf:type owl:NamedIndividual .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#stuck
:stuck rdf:type owl:NamedIndividual .


###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi

I guess because there's no path in your data from :Page which would go through only :renderBlock edges? Do you want paths which end with :renderBlock edges?

Best,
Pavel

better end in block1 block2
i want use class to render ui, those “blocks” class will have nodes connect to.

i think that query will return block1 block2 paths,but its empty

Yes, it's empty because there's no path in your data from :Page to either block via only :renderBlock edges. There's a path with first :renderTemplate and then :renderBlock.

Best,
Pavel

1 Like

okay i've got the idea, i replace :renderBlock to :renderTemplate, the path shows. but i want the nodes under :renderBlock, and in real data i don't know how many edges between my :keyword to :renderBlock, i want to query them recursively

it looks like i can write query like this

PATHS START ?s = :Page END ?o VIA {
    ?s (:renderTemplate/:renderBlock)+ ?o
}

but in real case the edge can be complicated

PATHS START ?s = :hell END ?o VIA {
    ?s (rdfs:subClassOf)+ ?x . # maybe a wildcard pattern here?
    ?x (:renderTemplate/:renderBlock)+ ?o
}

what about ?s (rdfs:subClassOf)+ ?x . can be anything, but there must has edge ":renderTemplate/:renderBlock" connect to ?START :renderTemplate/:renderBlock ?END

Would it be enough to restrict the set of end nodes to those reachable by renderBlock triples:

.. END ?o = { [] :renderBlock ?o } VIA { ...
1 Like

hi jess i've tried this in stardog studio, but it shows syntax error

Ah sorry, = should be removed.

1 Like

path query is awesome, yes this is exactly what i want

PATHS START ?s = :awesome END ?o { [] :renderBlock ?o } VIA ?p

@prefix : <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> .

<http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> rdf:type owl:Ontology .

#################################################################
#    Annotation properties
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderBlock
:renderBlock rdf:type owl:AnnotationProperty .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderTemplate
:renderTemplate rdf:type owl:AnnotationProperty .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block1
:Block1 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block2
:Block2 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Page
:Page rdf:type owl:Class ;
      :renderTemplate [ :renderBlock :Block1 ,
                                     :Block2
                      ] .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#hell
:hell rdf:type owl:Class ;
      rdfs:subClassOf :hello .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#hello
:hello rdf:type owl:Class ;
       rdfs:subClassOf :Page .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#yeah
:yeah rdf:type owl:Class ;
      rdfs:subClassOf :hell .


#################################################################
#    Individuals
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#awesome
:awesome rdf:type owl:NamedIndividual ,
                  :yeah .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#stuck
:stuck rdf:type owl:NamedIndividual .


###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi

Good to hear!

Best,
Jess

how to distinct result set with path query ?

The paths are already distinct. The path result consists of the nodes and edges between the start and end node. You can see that the second to last node in the path differs for each of the path pairs to blocks 1 and 2. You can ask for SHORTEST paths which it seems wouldn't make any difference here. You can LIMIT the number of paths returned but that wouldn't guarantee results for both blocks 1 and 2.

1 Like

okay after "CLEAN ALL" and "Add Data" again, the result seems right.

it looks anonymous/blank node (NO IRI) will create new tripples

That's correct. Each bnode without a label (eg []) will have a unique identity generated when it's added to the database.

1 Like

i've create two individuals, one in english and one in chinese, they both have same form.
and have owl:sameAs edge with their relates node but the chinese one return no result with same query

any possible an unicode support issue?

@prefix : <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> .

<http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4> rdf:type owl:Ontology .

#################################################################
#    Annotation properties
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderBlock
:renderBlock rdf:type owl:AnnotationProperty .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#renderTemplate
:renderTemplate rdf:type owl:AnnotationProperty .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block1
:Block1 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Block2
:Block2 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#Page
:Page rdf:type owl:Class ;
      :renderTemplate [ :renderBlock :Block1 ,
                                     :Block2
                      ] .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#hell
:hell rdf:type owl:Class ;
      rdfs:subClassOf :hello .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#hello
:hello rdf:type owl:Class ;
       rdfs:subClassOf :Page .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#yeah
:yeah rdf:type owl:Class ;
      rdfs:subClassOf :hell .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#法律
:法律 rdf:type owl:Class ;
    :renderTemplate [ :renderBlock :组织 ,
                                   :行为 ,
                                   :角色 ,
                                   :责任
                    ] .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#组织
:组织 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#行为
:行为 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#角色
:角色 rdf:type owl:Class .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#责任
:责任 rdf:type owl:Class .


#################################################################
#    Individuals
#################################################################

###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#amazing
:amazing rdf:type owl:NamedIndividual ;
         owl:sameAs :awesome .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#awesome
:awesome rdf:type owl:NamedIndividual ,
                  :yeah .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#stuck
:stuck rdf:type owl:NamedIndividual .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#中华人民共和国公司法
:中华人民共和国公司法 rdf:type owl:NamedIndividual ,
                     :法律 ;
            owl:sameAs :公司法 .


###  http://www.semanticweb.org/monsterstep/ontologies/2020/4/untitled-ontology-4#公司法
:公司法 rdf:type owl:NamedIndividual .


###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi

Are you using reasoning? If not, perhaps you need to traverse edges backwards too:

VIA {
 { ?s ?p ?o }
 UNION
 { ?o ?p ?s }
}
1 Like

after digging VIA UNION
i've found the reverse query will have tripples that i don't want even i didn't enable reasoning. its correct behavior i think. but what is the best way to restrict such a query

PATHS START ?start = :公司法 END ?end {
        [] :renderBlock ?end
      } VIA {
        { ?start ?edges ?end }
        UNION {
          ?end ?edges ?start
          #FILTER (?start NOT IN(owl:NamedIndividual, owl:Class))
        }
      }

i try to use FILTER function to get rid of them, but don't know if its the right way.

PATHS START ?start = :公司法 END ?end {
  [] :renderBlock ?end
} VIA {
  { ?start ?edges ?end }
  UNION {
    ?end ?edges ?start
    FILTER (?start NOT IN(owl:NamedIndividual, owl:Class))
  }
}

maybe can use FILTER IN with blank node?

How to query first matched renderBlock?

return renderTemplate that "world" related but not "Page"

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.