@Override public Stream<ConceptMap> expandHierarchies(Set<Var> toExpand) { if (toExpand.isEmpty()) return Stream.of(this); List<Set<Pair<Var, Concept>>> entryOptions = map.entrySet().stream() .map(e -> { Var var = e.getKey(); if (toExpand.contains(var)) { Concept c = get(var); if (c.isSchemaConcept()) { return ReasonerUtils.upstreamHierarchy(c.asSchemaConcept()).stream() .map(r -> new Pair<Var, Concept>(var, r)) .collect(Collectors.toSet()); } } return Collections.singleton(new Pair<>(var, get(var))); }).collect(Collectors.toList()); return Sets.cartesianProduct(entryOptions).stream() .map(mappingList -> new ConceptMapImpl(mappingList.stream().collect(Collectors.toMap(Pair::getKey, Pair::getValue)), this.explanation())) .map(ans -> ans.explain(explanation())); }
/** * Caches a concept so it does not have to be rebuilt later. * * @param concept The concept to be cached. */ public void cacheConcept(Concept concept){ conceptCache.put(concept.id(), concept); if(concept.isSchemaConcept()){ SchemaConcept schemaConcept = concept.asSchemaConcept(); schemaConceptCache.put(schemaConcept.label(), schemaConcept); labelCache.put(schemaConcept.label(), schemaConcept.labelId()); } }
@Override public Stream<ConceptSet> run(DeleteQuery query) { Stream<ConceptMap> answers = query.admin().match().stream().map(result -> result.project(query.admin().vars())).distinct(); // TODO: We should not need to collect toSet, once we fix ConceptId.id() to not use cache. // Stream.distinct() will then work properly when it calls ConceptImpl.equals() Set<Concept> conceptsToDelete = answers.flatMap(answer -> answer.concepts().stream()).collect(toSet()); conceptsToDelete.forEach(concept -> { if (concept.isSchemaConcept()) { throw GraqlQueryException.deleteSchemaConcept(concept.asSchemaConcept()); } concept.delete(); }); // TODO: return deleted Concepts instead of ConceptIds return Stream.of(new ConceptSet(conceptsToDelete.stream().map(Concept::id).collect(toSet()))); }
/** * * @param concept The concept to no longer track */ @SuppressWarnings("SuspiciousMethodCalls") public void remove(Concept concept){ modifiedThings.remove(concept); modifiedRoles.remove(concept); modifiedRelationshipTypes.remove(concept); modifiedRules.remove(concept); if(concept.isAttribute()) { newAttributes.removeAll(AttributeImpl.from(concept.asAttribute()).getIndex()); } if(concept.isRelationship()){ newRelationships.remove(concept.asRelationship()); } conceptCache.remove(concept.id()); if (concept.isSchemaConcept()) { Label label = concept.asSchemaConcept().label(); schemaConceptCache.remove(label); labelCache.remove(label); } }
if (concept.equals(otherConcept)) entryMap.put(var, concept); else { if (concept.isSchemaConcept() && otherConcept.isSchemaConcept() && !ReasonerUtils.areDisjointTypes(concept.asSchemaConcept(), otherConcept.asSchemaConcept())) { entryMap.put(
} else if (concept.isSchemaConcept()) { SchemaConcept ontoConcept = concept.asSchemaConcept(); output.append(colorKeyword("label ")).append(colorType(ontoConcept));
@Override protected Json concept(Concept concept) { Json json = Json.object("id", concept.id().getValue()); if (concept.isSchemaConcept()) { json.set("name", concept.asSchemaConcept().label().getValue()); SchemaConcept superConcept = concept.asSchemaConcept().sup(); if (superConcept != null) json.set("sub", superConcept.label().getValue()); } else if (concept.isThing()) { json.set("isa", concept.asThing().type().label().getValue()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } if (concept.isAttribute()) { json.set("value", concept.asAttribute().value()); } if (concept.isRule()) { Pattern when = concept.asRule().when(); if (when != null) { json.set("when", when.toString()); } Pattern then = concept.asRule().then(); if (then != null) { json.set("then", then.toString()); } } return json; }