@Nullable @Override public Rule getRule(String label) { SchemaConcept concept = getSchemaConcept(Label.of(label)); if (concept == null || !concept.isRule()) return null; return concept.asRule(); }
private static Map<Var, Type> getLabelVarTypeMap(EmbeddedGraknTx<?> tx, Set<Fragment> allFragments) { Map<Var, Type> labelVarTypeMap = new HashMap<>(); allFragments.stream() .filter(LabelFragment.class::isInstance) .forEach(fragment -> { // TODO: labels() should return ONE label instead of a set SchemaConcept schemaConcept = tx.getSchemaConcept( Iterators.getOnlyElement(((LabelFragment) fragment).labels().iterator())); if (schemaConcept != null && !schemaConcept.isRole() && !schemaConcept.isRule()) { labelVarTypeMap.put(fragment.start(), schemaConcept.asType()); } }); return labelVarTypeMap; }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ public static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.label(), superConcept); } }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ private static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.getLabel(), superConcept); } } }
private SchemaConcept putSchemaConcept() { SchemaConcept superConcept = use(SUPER_CONCEPT); Label label = use(LABEL); SchemaConcept concept; if (superConcept.isEntityType()) { concept = executor.tx().putEntityType(label); } else if (superConcept.isRelationshipType()) { concept = executor.tx().putRelationshipType(label); } else if (superConcept.isRole()) { concept = executor.tx().putRole(label); } else if (superConcept.isAttributeType()) { AttributeType attributeType = superConcept.asAttributeType(); AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.dataType()); concept = executor.tx().putAttributeType(label, dataType); } else if (superConcept.isRule()) { concept = executor.tx().putRule(label, use(WHEN), use(THEN)); } else { throw GraqlQueryException.insertMetaType(label, superConcept); } setSuper(concept, superConcept); return concept; }