/** * Reports whether or not this term is a number. * * @return <tt>false</tt> always. */ public boolean isNumber() { Term t = getValue(); return (t != this) && t.isNumber(); }
/** * Reports whether or not this term is a ground term. A variable is a ground term if it has been assigned a value * which is a ground term, and not otherwise. * * @return <tt>true</tt> if this variable has been assigned a ground term, <tt>false</tt> othewise. */ public boolean isGround() { Term t = getValue(); return (t != this) && t.isGround(); }
/** * Reports whether or not this term is constant (contains no variables). A variable is constant if it has been * assigned a value which is constant, and not otherwise. * * @return <tt>true</tt> if this term is constant, <tt>false</tt> otherwise. */ public boolean isConstant() { Term t = getValue(); return (t != this) && t.isConstant(); }
/** * Reports whether or not this term is constant (contains no variables). A variable is constant if it has been * assigned a value which is constant, and not otherwise. * * @return <tt>true</tt> if this term is constant, <tt>false</tt> otherwise. */ public boolean isConstant() { Term t = getValue(); return (t != this) && t.isConstant(); }
/** * Reports whether or not this term is an atom. A variable is an atom if it has been assigned a value which is an * atom and not otherwise. * * @return <tt>true</tt> if this variable has been assigned atomic value, <tt>false</tt> otherwise. */ public boolean isAtom() { Term t = getValue(); return (t != this) && t.isAtom(); }
/** * Reports whether or not this term is a ground term. A variable is a ground term if it has been assigned a value * which is a ground term, and not otherwise. * * @return <tt>true</tt> if this variable has been assigned a ground term, <tt>false</tt> othewise. */ public boolean isGround() { Term t = getValue(); return (t != this) && t.isGround(); }
/** * Reports whether or not this term is a number. * * @return <tt>false</tt> always. */ public boolean isNumber() { Term t = getValue(); return (t != this) && t.isNumber(); }
/** * Reports whether or not this term is compound. A variable is compound if it has been assigned a value which is * compound, and not otherwise. * * @return <tt>true</tt> if this term is compound, <tt>fals</tt> otherwise. */ public boolean isCompound() { Term t = getValue(); return (t != this) && t.isCompound(); }
/** * Reports whether or not this term is an atom. A variable is an atom if it has been assigned a value which is an * atom and not otherwise. * * @return <tt>true</tt> if this variable has been assigned atomic value, <tt>false</tt> otherwise. */ public boolean isAtom() { Term t = getValue(); return (t != this) && t.isAtom(); }
/** * Reports whether or not this term is compound. A variable is compound if it has been assigned a value which is * compound, and not otherwise. * * @return <tt>true</tt> if this term is compound, <tt>fals</tt> otherwise. */ public boolean isCompound() { Term t = getValue(); return (t != this) && t.isCompound(); }
/** * Gets the actual value of a term, which is either the term itself, or in the case of variables, the value that is * currently assigned to the variable. When the variable is free, the variable term itself is returned. * * @return The term itself, or the assigned value of this variable. */ public Term getValue() { Variable storageCell = getStorageCell(this); if (storageCell == null) { return this; } else { return storageCell.getValue(); } }
/** * Extracts all restricted int types from the type checked model and caches them in 'catalogueTypes' parameter by * name. * * @param catalogueTypes The map to build up the catalogue types in. */ private void initializeAllRestrictedIntTypes(Map<String, Type> catalogueTypes) { String queryString = "?-normal_type(integer_range, MN, JT, _MP), member(from(From), _MP), member(to(To), _MP)."; Iterable<Map<String, Variable>> bindingsIterable = runQuery(queryString); for (Map<String, Variable> bindings : bindingsIterable) { String typeName = engine.getFunctorName((Functor) bindings.get("MN").getValue()); String javaTypeName = engine.getFunctorName((Functor) bindings.get("JT").getValue()); NumericType fromTerm = (NumericType) bindings.get("From").getValue(); NumericType toTerm = (NumericType) bindings.get("To").getValue(); if ("int".equals(javaTypeName)) { catalogueTypes.put(typeName, IntRangeType.createInstance(typeName, fromTerm.intValue(), toTerm.intValue())); } else if ("long".equals(javaTypeName)) { } } }
/** * Extracts the natural key fields for a named component type in the catalogue model. Not all components have * natural key fields, in which case the resulting set of fields will be empty. * * @param name The name of the component type to get the natural key fields of. * * @return The natural key fields of a named component type. */ private Set<String> getNaturalKeyFields(String name) { String queryString = "?- nat_key_field(" + name + ", F)."; Iterable<Map<String, Variable>> uniqueFieldsIterable = runQuery(queryString); Set<String> results = new LinkedHashSet<String>(); for (Map<String, Variable> variables : uniqueFieldsIterable) { Variable var = variables.get("F"); Functor fieldFunctor = (Functor) var.getValue(); String fieldName = engine.getFunctorName(fieldFunctor); results.add(fieldName); } return results; }
/** * Compares this term for structural equality with another. Two terms are structurally equal if they are the same * functor with the same arguments, or are the same unbound variable, or the bound values of the left or right * variable operands are structurally equal. Structural equality is a stronger equality than unification and unlike * unification it does not produce any variable bindings. Two unified terms will always be structurally equal. * * @param term The term to compare with this one for structural equality. * * @return <tt>true</tt> if the two terms are structurally eqaul, <tt>false</tt> otherwise. */ public boolean structuralEquals(Term term) { Term comparator = term.getValue(); Term value = getValue(); // Check if this is an unbound variable in which case the comparator must be the same variable. if (value == this) { return this.equals(comparator); } else { return value.structuralEquals(comparator); } }
/** * Compares this term for structural equality with another. Two terms are structurally equal if they are the same * functor with the same arguments, or are the same unbound variable, or the bound values of the left or right * variable operands are structurally equal. Structural equality is a stronger equality than unification and unlike * unification it does not produce any variable bindings. Two unified terms will always be structurally equal. * * @param term The term to compare with this one for structural equality. * * @return <tt>true</tt> if the two terms are structurally eqaul, <tt>false</tt> otherwise. */ public boolean structuralEquals(Term term) { Term comparator = term.getValue(); Term value = getValue(); // Check if this is an unbound variable in which case the comparator must be the same variable. if (value == this) { return this.equals(comparator); } else { return value.structuralEquals(comparator); } }
/** * Extracts all restricted real types from the type checked model and caches them in the 'catalogueTypes' parameter * by name. * * @param catalogueTypes The map to build up the catalogue types in. */ private void initializeAllRestrictedRealTypes(Map<String, Type> catalogueTypes) { String queryString = "?-normal_type(real_range, MN, JT, _MP), member(from(From), _MP), member(to(To), _MP)."; Iterable<Map<String, Variable>> bindingsIterable = runQuery(queryString); for (Map<String, Variable> bindings : bindingsIterable) { String typeName = engine.getFunctorName((Functor) bindings.get("MN").getValue()); String javaTypeName = engine.getFunctorName((Functor) bindings.get("JT").getValue()); NumericType fromTerm = (NumericType) bindings.get("From").getValue(); NumericType toTerm = (NumericType) bindings.get("To").getValue(); if ("float".equals(javaTypeName)) { catalogueTypes.put(typeName, FloatRangeType.createInstance(typeName, fromTerm.floatValue(), toTerm.floatValue())); } else if ("double".equals(javaTypeName)) { catalogueTypes.put(typeName, DoubleRangeType.createInstance(typeName, fromTerm.doubleValue(), toTerm.doubleValue())); } } }
/** * Extracts all enum types from the type checked model and caches them in the 'catalogueTypes' parameter by name. * * @param catalogueTypes The map to build up the catalogue types in. */ private void initializeAllEnumTypes(Map<String, Type> catalogueTypes) { String queryString = "?-normal_type(enumeration_type, MN, enumeration, _MP), member(labels(L), _MP)."; Iterable<Map<String, Variable>> bindingsIterable = runQuery(queryString); for (Map<String, Variable> enumBindings : bindingsIterable) { Variable nameVar = enumBindings.get("MN"); String typeName = engine.getFunctorName((Functor) nameVar.getValue()); Variable labelsVar = enumBindings.get("L"); Iterable<Term> labelsList = (RecursiveList) labelsVar.getValue(); Collection<String> labelNames = new LinkedList<String>(); for (Term levelTerm : labelsList) { labelNames.add(engine.getFunctorName((Functor) levelTerm)); } EnumeratedStringAttribute.EnumeratedStringAttributeFactory factory = EnumeratedStringAttribute.getFactoryForClass(typeName); for (String label : labelNames) { factory.createStringAttribute(label); } catalogueTypes.put(typeName, factory.getType()); } }
/** * Queries the relationships between components, to find which components have no incoming relationship links by * composition, and are therefore not wholly owned by other components and can be considered to be top-level. * * @param catalogueTypes The types in the catalogue to extract the top-level feature of. */ private void initializeAllTopLevel(Map<String, Type> catalogueTypes) { // Query for all top-level entities. String queryString = "?-top_level_entity(Name)."; Iterable<Map<String, Variable>> fieldBindingsIterable = runQuery(queryString); for (Map<String, Variable> variables : fieldBindingsIterable) { String componentName = engine.getFunctorName((Functor) variables.get("Name").getValue()); // Check if the top-level entity was in the list of types to extract. Type type = catalogueTypes.get(componentName); if (type instanceof EntityType) { ComponentType entityType = (EntityType) type; State metaModel = entityType.getMetaModel(); metaModel.setProperty("topLevel", true); } } }
/** * Prints a variable binding in the form 'Var = value'. * * @param var The variable to print. * * @return The variable binding in the form 'Var = value'. */ public String printVariableBinding(Variable var) { return var.toString(getInterner(), true, false) + " = " + var.getValue().toString(getInterner(), false, true); }