How to exclude PREFIX in result with PATH START END VIA Query?

my query is

PATHS START ?start = :公司法 END ?end {
    ?end :广义? [].
    FILTER NOT EXISTS { ?end :广义 [] }
} VIA :广义

i want to exclude PREFIX in result

{
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#公司法": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#公司法"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#客体"
    }
  }
}

to this

{
  "公司法": {
    "start": {
      "type": "uri",
      "value": "公司法"
    },
    "end": {
      "type": "uri",
      "value": "法律"
    }
  },
  "法律": {
    "start": {
      "type": "uri",
      "value": "法律"
    },
    "end": {
      "type": "uri",
      "value": "文件"
    }
  },
  "文件": {
    "start": {
      "type": "uri",
      "value": "文件"
    },
    "end": {
      "type": "uri",
      "value": "媒体"
    }
  },
  "媒体": {
    "start": {
      "type": "uri",
      "value": "媒体"
    },
    "end": {
      "type": "uri",
      "value": "客体"
    }
  }
}

Hey. We don't provide any automatic method of performing this transformation. It will have to be done on the client.

I was just reading the docs on the new "stored query service" feature and came across this understated section,

" Another interesting feature is the ability to call path queries from SELECT / CONSTRUCT / ASK queries. One cannot directly use a path query in a subquery because those do not return SPARQL binding sets, aka solutions (we discussed that issue in an earlier blog post on Extended Solutions). However, this service circumvents that restriction:"

I don't know exactly what your data looks like or if the query results need to look exactly like this but you might have some luck with using your path query as a stored subquery and binding labels in the outer query.

for a SELECT QUERY i could use "afn:localname" mention in other post, but i can't figure out how it done with PATH query

      SELECT
        ?prefLabel
        (afn:localname(?broaderConceptUri) as ?broaderConceptId)
        (afn:localname(?conceptURI) as ?conceptId)
      WHERE {
        :${conceptId} (skos:broader|skos:narrower)+ ?broaderConceptUri .
        ?broaderConceptUri skos:narrower ?conceptURI .
        ?broaderConceptUri skosxl:prefLabel ?prefLabelId .
        ?prefLabelId skosxl:literalForm ?prefLabel .
      }

how should i return skosxl:prefLabel/skosxl:literalForm with path query?

the ?start ?end is a skos:Concept, and the display label is a skosxl:prefLabel(another URI) has skosxl:literalForm as label i want to use it to show a UI

or should i use second SELECT query to find label?

this result is just normal json return by PATH query, then i use lodash keyBy on 'start'. sorry if its miss leading

PATHS START ?start = :公司法 END ?end {
    ?end :广义? [].
    FILTER NOT EXISTS { ?end :广义 [] }
} VIA :广义
{
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#公司法": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#公司法"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#法律"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#文件"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体"
    }
  },
  "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体": {
    "start": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#媒体"
    },
    "end": {
      "type": "uri",
      "value": "http://www.semanticweb.org/monsterstep/ontologies/2020/6/untitled-ontology-46#客体"
    }
  }
}

how should i return skosxl:prefLabel/skosxl:literalForm with path query?

the ?start ?end is a skos:Concept, and the display label is a skosxl:prefLabel(another URI) has skosxl:literalForm as label i want to use it to show a UI

You can bind variables in the start/end patterns. You already have a pattern for the END nodes here constraining them, you just need to add in the additional properties you want to query. Check out the example in Home | Stardog Documentation Latest

1 Like

You can use the same approach as above to BIND the result of the localname function, eg.

PATHS
START ?start
{
  BIND(:公司法 as ?start)
  ?start :prefLabel ?label
  BIND(localname(?start) as ?startLocal)
}
END ?end { # same thing

This will work only for the start/end nodes. You can do the same thing in intermediate nodes, but shouldn't use that for the start/end as it will be much more expensive to traverse.

1 Like

i end up with this

the PREFIX and skosxl label both show in result set awesome~

thanks jess

PATHS START ?start = :${conceptId} END ?end {
        ?end skos:broader? [] .
        FILTER NOT EXISTS { ?end skos:broader [] }
      } VIA {
        ?start skos:broader ?end .
        ?start skosxl:prefLabel/skosxl:literalForm ?startLabel .
        ?end skosxl:prefLabel/skosxl:literalForm ?endLabel .
        BIND(localname(?start) as ?startLocal) .
        BIND(localname(?end) as ?endLocal) .
      }
[
   {
     "startLocal": {
       "type": "literal",
       "value": "gv8PcCNNt2a9MEwRC"
     },
     "startLabel": {
       "type": "literal",
       "value": "公司法"
     },
     "start": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#gv8PcCNNt2a9MEwRC"
     },
     "end": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#Z8gNi7u8oE3g4mZcX"
     },
     "endLocal": {
       "type": "literal",
       "value": "Z8gNi7u8oE3g4mZcX"
     },
     "endLabel": {
       "type": "literal",
       "value": "法律法规"
     }
   },
   {
     "startLocal": {
       "type": "literal",
       "value": "Z8gNi7u8oE3g4mZcX"
     },
     "startLabel": {
       "type": "literal",
       "value": "法律法规"
     },
     "start": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#Z8gNi7u8oE3g4mZcX"
     },
     "end": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#72BxdgfYoqEwwLLrA"
     },
     "endLocal": {
       "type": "literal",
       "value": "72BxdgfYoqEwwLLrA"
     },
     "endLabel": {
       "type": "literal",
       "value": "文件"
     }
   },
   {
     "startLocal": {
       "type": "literal",
       "value": "Z8gNi7u8oE3g4mZcX"
     },
     "startLabel": {
       "type": "literal",
       "value": "文件"
     },
     "start": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#72BxdgfYoqEwwLLrA"
     },
     "end": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#vyY5gbgBY7kFQKANw"
     },
     "endLocal": {
       "type": "literal",
       "value": "vyY5gbgBY7kFQKANw"
     },
     "endLabel": {
       "type": "literal",
       "value": "媒体"
     }
   },
   {
     "startLocal": {
       "type": "literal",
       "value": "Z8gNi7u8oE3g4mZcX"
     },
     "startLabel": {
       "type": "literal",
       "value": "媒体"
     },
     "start": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#vyY5gbgBY7kFQKANw"
     },
     "end": {
       "type": "uri",
       "value": "https://un.jong.kim/onto#g3GTJX2ErAYBL8HJq"
     },
     "endLocal": {
       "type": "literal",
       "value": "g3GTJX2ErAYBL8HJq"
     },
     "endLabel": {
       "type": "literal",
       "value": "客体"
     }
   }
 ]
1 Like

Looks good! Glad it's working.

1 Like

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