plazi / taxomplete

Allows auto-completion of species in an input field
0 stars 0 forks source link

Poor man's text index #4

Closed retog closed 4 years ago

retog commented 4 years ago

Idea: by adding triples pointing to the first two lowercased characters of the genus and the species we can greatly reduce the number of triples for which the filters have to be evaluated.

retog commented 4 years ago
retog commented 4 years ago

This should generate the index:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dwc: <http://rs.tdwg.org/dwc/terms/>
PREFIX dwcfp: <http://filteredpush.org/ontologies/oa/dwcFP#>
PREFIX tp: <https://vocab.plazi.org/taxomplete/>
INSERT { GRAPH tp:Index { 
  ?res tp:genusPrefix ?prefix
  } } WHERE {
  ?res dwc:genus ?genus .
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?genus) > 1)
  BIND(LCASE(substr(?genus,1,2)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:speciesPrefix ?prefix
  } } WHERE {
  ?res dwc:species ?species.
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?species) > 1)
  BIND(LCASE(substr(?species,1,2)) AS $prefix)
}
retog commented 4 years ago

This generates indexes for 3 lengths:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dwc: <http://rs.tdwg.org/dwc/terms/>
PREFIX dwcfp: <http://filteredpush.org/ontologies/oa/dwcFP#>
PREFIX tp: <https://vocab.plazi.org/taxomplete/>
INSERT { GRAPH tp:Index { 
  ?res tp:genusPrefix2 ?prefix
  } } WHERE {
  ?res dwc:genus ?genus .
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?genus) > 1)
  BIND(LCASE(substr(?genus,1,2)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:speciesPrefix2 ?prefix
  } } WHERE {
  ?res dwc:species ?species.
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?species) > 1)
  BIND(LCASE(substr(?species,1,2)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:genusPrefix3 ?prefix
  } } WHERE {
  ?res dwc:genus ?genus .
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?genus) > 2)
  BIND(LCASE(substr(?genus,1,3)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:speciesPrefix3 ?prefix
  } } WHERE {
  ?res dwc:species ?species.
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?species) > 2)
  BIND(LCASE(substr(?species,1,3)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:genusPrefix4 ?prefix
  } } WHERE {
  ?res dwc:genus ?genus .
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?genus) > 3)
  BIND(LCASE(substr(?genus,1,4)) AS $prefix)
};
INSERT { GRAPH tp:Index { 
  ?res tp:speciesPrefix4 ?prefix
  } } WHERE {
  ?res dwc:species ?species.
  ?res rdf:type dwcfp:TaxonName.
  FILTER (strlen(?species) > 3)
  BIND(LCASE(substr(?species,1,4)) AS $prefix)
}