* @param result the result of the triple query to cache
*/
public void cacheTriples(KiWiResource subject, KiWiUriResource property, KiWiNode object, KiWiResource context, boolean inferred, List<KiWiTriple> result) {
// cache the query result
IntArray key = createCacheKey(subject,property,object,context,inferred);
queryCache.put(new Element(key,result));
// cache the nodes of the triples and the triples themselves
Set<KiWiNode> nodes = new HashSet<KiWiNode>();
for(KiWiTriple triple : result) {
Collections.addAll(nodes, new KiWiNode[]{triple.getSubject(), triple.getObject(), triple.getPredicate(), triple.getContext()});
queryCache.put(new Element(createCacheKey(triple.getSubject(),triple.getPredicate(),triple.getObject(),triple.getContext(),triple.isInferred()), ImmutableList.of(triple)));
}
// special optimisation: when only the subject (and optionally context) is given, we also fill the caches for
// all property values
if(subject != null && property == null && object == null) {
HashMap<KiWiUriResource,List<KiWiTriple>> properties = new HashMap<KiWiUriResource, List<KiWiTriple>>();
for(KiWiTriple triple : result) {
List<KiWiTriple> values = properties.get(triple.getPredicate());
if(values == null) {
values = new LinkedList<KiWiTriple>();
properties.put(triple.getPredicate(),values);
}
values.add(triple);
}
for(Map.Entry<KiWiUriResource,List<KiWiTriple>> entry : properties.entrySet()) {
IntArray key2 = createCacheKey(subject,entry.getKey(),null,context,inferred);
queryCache.put(new Element(key2,entry.getValue()));
}
}