1:- module(search_util,
    2          [
    3           % must be exposed so it can be expanded in query rewrites
    4           label_or_synonym_pred_hook/1,
    5
    6           lmatch/2,
    7           
    8           psearch/5,
    9           psearch/4,
   10           psearch/3,
   11
   12           tsearch/6,
   13           tsearch/5,
   14           tsearch/4,
   15           tsearch/3,
   16           tsearch/2,
   17           
   18           lsearch/2,
   19           lsearch/3,
   20           lsearch/4,
   21           lsearch/5
   22          ]).   23
   24:- use_module(library(semweb/rdf11)).   25:- use_module(library(semweb/rdfs)).   26:- use_module(library(sparqlprog/owl_util)).   27%:- use_module(library(sparqlprog/ontologies/owl), [label/2]).
   28:- use_module(library(sparqlprog/emulate_builtins)).
 lmatch(+Pattern:atom, ?Object) is nondet
Uses swi-prolog rdf11 'like' matching:
   36lmatch(P,C) :-   {like(L,P)},rdf(C,rdfs:label,L).
 lsearch(+Pattern, ?Object, ?Label, +Flags:str, ?Graph) is nondet
search for objects with an rdfs:label matching Pattern
   42lsearch(P,C,L,F,G) :-   rdf(C,rdfs:label,L,G),regex(str(L),P,F).
   43lsearch(P,C,L,F) :-   label(C,L),regex(str(L),P,F).
   44lsearch(P,C,L) :-   label(C,L),regex(str(L),P,"i").
   45lsearch(P,C) :-   label(C,L),regex(str(L),P,"i").
 lsearch(+Pattern, ?Object, ?Pred, ?Label, +Flags:str) is nondet
search for objects with any property matching Pattern
   50psearch(P,C,R,L,F) :-   rdf(C,R,L),regex(str(L),P,F).
   51psearch(P,C,R,L) :-   rdf(C,R,L),regex(str(L),P,"i").
   52psearch(P,C,R) :-   rdf(C,R,L),regex(str(L),P,"i").
 tsearch(+Pattern, ?Object, ?Label, +Flags:str, ?Graph) is nondet
term search: find objects with an rdfs:label or synonym-like property matching Pattern
   57tsearch(P,C,Pred,L,F,G) :-   label_or_synonym_pred_hook(Pred), rdf(C,Pred,L,G),regex(str(L),P,F).
   58tsearch(P,C,Pred,L,F) :-   tsearch(P,C,Pred,L,F,_).
   59tsearch(P,C,Pred,L) :-   tsearch(P,C,Pred,L,"i",_).
   60tsearch(P,C,Pred) :-   tsearch(P,C,Pred,_,"i",_).
   61tsearch(P,C) :-   tsearch(P,C,_,_,"i",_).
   62
   63:- rdf_meta label_or_synonym_pred_hook(r).
   64:- multifile label_or_synonym_pred_hook/1.   65label_or_synonym_pred_hook(rdfs:label).
   66label_or_synonym_pred_hook('http://www.geneontology.org/formats/oboInOwl#hasRelatedSynonym').
   67label_or_synonym_pred_hook('http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym').
   68label_or_synonym_pred_hook('http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym').
   69label_or_synonym_pred_hook('http://www.geneontology.org/formats/oboInOwl#hasExactSynonym')