4.5.1 Literal maps: Creating additional indices on literals
‘Literal maps' provide a relation between literal values, intended to create additional indexes on literals. The current implementation can only deal with integers and atoms (string literals). A literal map maintains an ordered set of keys. The ordering uses the same rules as described in section 4.5. Each key is associated with an ordered set of values. Literal map objects can be shared between threads, using a locking strategy that allows for multiple concurrent readers.
Typically, this module is used together with rdf_monitor/2
on the channals new_literal
and old_literal
to
maintain an index of words that appear in a literal. Further abstraction
using Porter stemming or Metaphone can be used to create additional
search indices. These can map either directly to the literal values, or
indirectly to the plain word-map. The SWI-Prolog NLP package provides
complimentary building blocks, such as a tokenizer, Porter stem and
Double Metaphone.
- rdf_new_literal_map(-Map)
- Create a new literal map, returning an opaque handle.
- rdf_destroy_literal_map(+Map)
- Destroy a literal map. After this call, further use of the Map handle is illegal. Additional synchronisation is needed if maps that are shared between threads are destroyed to guarantee the handle is no longer used. In some scenarios rdf_reset_literal_map/1 provides a safe alternative.
- rdf_reset_literal_map(+Map)
- Delete all content from the literal map.
- rdf_insert_literal_map(+Map, +Key, +Value)
- Add a relation between Key and Value to the map. If this relation already exists no action is performed.
- rdf_insert_literal_map(+Map, +Key, +Value, -KeyCount)
- As rdf_insert_literal_map/3.
In addition, if Key is a new key in
Map, unify KeyCount with the number of keys in Map.
This serves two purposes. Derived maps, such as the stem and metaphone
maps need to know about new keys and it avoids additional foreign calls
for doing the progress in
rdf_litindex.pl
. - rdf_delete_literal_map(+Map, +Key)
- Delete Key and all associated values from the map. Succeeds always.
- rdf_delete_literal_map(+Map, +Key, +Value)
- Delete the association between Key and Value from the map. Succeeds always.
- [det]rdf_find_literal_map(+Map, +KeyList, -ValueList)
- Unify ValueList with an ordered set of values associated to
all keys from KeyList. Each key in KeyList is
either an atom, an integer or a term
not(Key)
. If not-terms are provided, there must be at least one positive keywords. The negations are tested after establishing the positive matches. - rdf_keys_in_literal_map(+Map, +Spec, -Answer)
- Realises various queries on the key-set:
- all
- Unify Answer with an ordered list of all keys.
- key(+Key)
- Succeeds if Key is a key in the map and unify Answer with the number of values associated with the key. This provides a fast test of existence without fetching the possibly large associated value set as with rdf_find_literal_map/3.
- prefix(+Prefix)
- Unify Answer with an ordered set of all keys that have the given prefix. Prefix must be an atom. This call is intended for auto-completion in user interfaces.
- ge(+Min)
- Unify Answer with all keys that are larger or equal to the integer Min.
- le(+Max)
- Unify Answer with all keys that are smaller or equal to the integer Max.
- between(+Min, +Max)
- Unify Answer with all keys between Min and Max (including).
- rdf_statistics_literal_map(+Map, +Key(-Arg...))
- Query some statistics of the map. Provides keys are:
- size(-Keys, -Relations)
- Unify Keys with the total key-count of the index and Relation with the total Key-Value count.