Skip to content

webdsl-search.stx

pdmosses/webdsl-statix/webdslstatix/trans/static-semantics/webdsl-search.stx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module static-semantics/webdsl-search

imports
  static-semantics/types/built-ins

  static-semantics/webdsl
  static-semantics/webdsl-types

signature

  relations
     : string * string

rules // definition

  defOk(_, FullTextAnalyzer(_, _, _)) :- try { false } | warning $[This definition is not yet implemented].
  defOk(_, SearchMapping(_, _)) :- try { false } | warning $[This definition is not yet implemented].

rules // search retrieval expressions

  typeOfExp(s, RetrievalExp(exp)) = typeOfRetrievalExp(s, exp).

   : scope * RetrievalExp -> TYPE
  typeOfRetrievalExp(s, Highlight(_, _, _, searcherExp)) = string() :-
    isEntitySearcher(s, typeOfExp(s, searcherExp)).

  typeOfRetrievalExp(, HighlightTags(_, _, _, searcherExp, _, _)) = string(s) :-
    isEntitySearcher(s, typeOfExp(s, searcherExp)).

  typeOfRetrievalExp(, SearchResults(exp)) = LIST(t) :- {  }
    searcherType == typeOfExp(s, exp),
    isEntitySearcher(s, searcherType) | error $[Expression must be an entity searcher, got [searcherType]],
    t == entityOfSearcher(s, searcherType) | error $[Cannot resolve entity of searcher with type [searcherType]].

  typeOfRetrievalExp(s, FacetResults(_, searcherExp)) = LIST(definedTypeIfExists(, "Facet")) :-
    isEntitySearcher(s, typeOfExp(s, searcherExp)).

  typeOfRetrievalExp(s, SearchResultsSize(exp)) = int() :-
    isEntitySearcher(s, typeOfExp(s, exp)).

  typeOfRetrievalExp(s, SearchTimeString(exp)) = string() :- 
    isEntitySearcher(s, typeOfExp(s, exp)).

  typeOfRetrievalExp(s, Suggest(_, _, _)) = LIST(string(s)).

rules // search initialization expressions

  typeOfExp(s, SearcherDef(def)) = typeOfSearcherDef(s, def).

   : scope * SearcherDef -> TYPE
  typeOfSearcherDef(, SearcherInit(, parts)) = t :- {  }
    ent == definedType(s, e) | error $[Cannot resolve entity [e]] @e,
    t == searcherOfEntity(s, ent) | error $[Cannot resolve entity searcher for type [e]] @e,
    searcherPartsOk(s, parts).

  typeOfSearcherDef(, SearcherRefMod(, parts)) =  :-
    t == typeOfExp(s, exp),
    isEntitySearcher(s, t) | error $[Expression must be an entity searcher, got type [t]] @exp,
    searcherPartsOk(s, parts).

rules // searcher parts

   maps searcherPartOk(*, list(*))
   : scope * SearcherPart
  searcherPartOk(_, part) :- try { false } | warning $[Searcher part [part] is not yet implemented].

rules // entity name to searcher name mapping

   : scope * TYPE
  isEntitySearcher(s, t) :- false.
  isEntitySearcher(s, NATIVECLASS(name, _)) :-
    resolveSearcherMappingInverse(s, name) == [_].

   : scope * string -> list((path * (string * string)))
  resolveSearcherMapping(s, entity) = ps :-
    query searcher filter P* F* ((EXTEND? INHERIT*) | (DEF? (IMPORT | IMPORTLIB)?))
           and { e' :- e' == (entity, _) }
           in s |-> ps.

   : scope * string -> list((path * (string * string)))
  resolveSearcherMappingInverse(s, searcher) = ps :-
    query searcher filter P* F* ((EXTEND? INHERIT*) | (DEF? (IMPORT | IMPORTLIB)?))
           and { e' :- e' == (_, searcher) }
           in s |-> ps.

  defOk(s, GeneratedDefinition(Generated(["entitySearcherMapping", entity, searcher]))) :-
    !searcher[entity, searcher] in s.

   : scope * TYPE -> TYPE
  searcherOfEntity(_, _) = UNTYPED() :- false.
  searcherOfEntity(, ENTITY(e, _)) = t :- {  }
    resolveSearcherMapping(s, e) == [(_, (_, searcher))],
    t == definedTypeNoRef(s, searcher).

   : scope * TYPE -> TYPE
  entityOfSearcher(_, _) = UNTYPED() :- false.
  entityOfSearcher(, NATIVECLASS(searcher, _)) = t :- {  }
    resolveSearcherMappingInverse(s, searcher) == [(_, (entity, _))],
    t == definedTypeNoRef(s, entity).

rules // built in

   : scope
  declareSearchBuiltIns(s) :-
    !searcher["Entity", "Searcher"] in s. // abstract searcher results in entity type