IBM / kif

A Wikidata-based framework for integrating knowledge sources
https://ibm.github.io/kif/
Apache License 2.0
9 stars 2 forks source link

Store: Alternative approach for matching properties #11

Closed gflima closed 4 months ago

gflima commented 8 months ago
select * where {
  ?subject ?p ?wds .
  ?wds <http://wikiba.se/ontology#rank> _:b0 .
  ?wds <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology#BestRank> .
  ?property wikibase:claim ?p .
  ?property wikibase:statementProperty ?ps .
  ?property wikibase:statementValue ?psv .
  ?property wikibase:novalue ?wdno .
#   bind(substr(str(?p), 30) as ?pname)
#   bind(uri(concat("http://www.wikidata.org/entity/", ?pname)) as ?property)
#   bind(uri(concat("http://www.wikidata.org/prop/statement/", ?pname)) as ?ps)
#   bind(uri(concat("http://www.wikidata.org/prop/statement/value/", ?pname)) as ?psv)
#   bind(uri(concat("http://www.wikidata.org/prop/novalue/", ?pname)) as ?wdno)
  {
    ?wds ?ps ?value .
    optional {
      {
        ?wds ?psv ?wdv .
        ?wdv <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology#QuantityValue> .
        ?wdv <http://wikiba.se/ontology#quantityAmount> ?qt_amount .
        optional {
          ?wdv <http://wikiba.se/ontology#quantityUnit> ?qt_unit .
        }
        optional {
          ?wdv <http://wikiba.se/ontology#quantityLowerBound> ?qt_lower .
        }
        optional {
          ?wdv <http://wikiba.se/ontology#quantityUpperBound> ?qt_upper .
        }
      }
      union {
        ?wds ?psv ?wdv .
        ?wdv <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology#TimeValue> .
        ?wdv <http://wikiba.se/ontology#timeValue> ?tm_value .
        optional {
          ?wdv <http://wikiba.se/ontology#timePrecision> ?tm_precision .
        }
        optional {
          ?wdv <http://wikiba.se/ontology#timeTimezone> ?tm_timezone .
        }
        optional {
          ?wdv <http://wikiba.se/ontology#timeCalendarModel> ?tm_calendar .
        }
      }
    }
  }
  union {
    ?wds <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?wdno .
  }
  values (?i ?subject ?property ?pname ?p ?ps ?psv ?wdno ?value ?qt_amount ?qt_unit ?qt_lower ?qt_upper ?tm_value ?tm_precision ?tm_timezone ?tm_calendar) {
    ("0"^^<http://www.w3.org/2001/XMLSchema#integer> UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF UNDEF)
  }
} limit 3 offset 0
gflima commented 8 months ago

See, for example:

select * where {
  wd:P31 wikibase:propertyType ?type.
  wd:P31 ?x ?y.
  filter(strstarts(str(?x), "http://wikiba.se/ontology#"))
} limit 30

image

gflima commented 8 months ago

Related: It seems that we can use the following to test whether something is an item:

select ?x  where {
  ?x wikibase:identifiers _:b.
} limit 100
gflima commented 7 months ago

Another advantage: We can get the property datatype for free.

gflima commented 4 months ago

We are using this approach in the pattern API.