ilog.rules.vocabulary.model.bom

Class IlrBOMVocabularyBuilder

  • java.lang.Object
    • ilog.rules.vocabulary.model.bom.IlrBOMVocabularyBuilder
  • All Implemented Interfaces:
    ilog.rules.vocabulary.model.IlrVocabularyConstants


    public class IlrBOMVocabularyBuilder
    extends java.lang.Object
    implements ilog.rules.vocabulary.model.IlrVocabularyConstants
    This class is a helper to create a Vocabulary from an Object Model. It provides API to create Concepts, Concept Instances and Phrases that are related to some Object Model elements: classes, attributes and methods. This class can be used to create a vocabulary from an external representation of an Object Model and from an external representation of the verbalization. The vocabulary built from this API is a composite vocabulary that includes a Boot vocabulary (including all basic types) and a user vocabulary that is filled-in with user vocabulary elements created using the API of this class. The typical usage of this class is described by the following pseudo-code: // create a builder for a given Locale IlrBOMVocabularyBuilder builder = new IlrBOMVocabularyBuilder(Locale.US); // create vocabulary elements using addConcept(), addConceptInstance(), addAttributePhrase() and addMethodPhrase() APIs ... // retrieve the created vocabulary that can be used to initialize a BRL parser for instance IlrVocabulary voc = builder.getVocabulary(); Another usage of this class is to use one of its helper method which creates the default vocabulary for a given full-filled business object model. See generateBOMVocabulary(...) static method in this class.. In this case, you relies on the default locale-specific verbalizer to compute a verbalization for the given object model. Type Section An object model represents a type system. A type system usually features a set of Primitive types. The underlying type system of a Vocabulary relies on a set of primitive types. When specifying the type of an attribute, of method return type or method arguments, you can refer to any User types you have, using their fully-qualified-names or the following primitive types:
    • void
    • object
    • string
    • boolean
    • int
    • long
    • float
    • double
    • char
    • date: this type corresponds to a simple date with the day, the month, the year
    • dateTime: this type corresponds to a full date with date and time informations
    • time: this time is a time type with hour, minutes, second and AM/PM information
    • universalDate: this type is a universal date with date, time and timezone informations
    • universalTime: this type is a universal time with time, AM/PM and timezone information
    • dayOfWeek: this type is an enum of locale-specific days of week
    • month: this type is an enum of locale-specific months
    • year: this type is a number verbalized as "the year 2010"
    Collection A Vocabulary supports the definition of n-ary relationships between concepts. These collection relationships are mapped on array type in the object model. So each time a object model type is referenced, you can pass an array of this type to create a n-ary relationships whose elements are of the given type. Object Model element names Vocabulary elements created by this API have an id, that usually correspond to the identifier of the Object Model element. When passed to this API, this class id must be a qualified Java Identifier as accepted by SourceVersion.isName() JDK helper. Attribute or method name must be a Java Identifier as accepted by SourceVersion.isIdentifier() JDK helper. It also cannot be a Java keyword as specified by SourceVersion.isKeyword(). The getBOMIdentifier() API allows to get a compliant id from any given identifier.
    • Field Detail

      • COLLECTION_ATTRIBUTE

        public static final java.lang.String COLLECTION_ATTRIBUTE
        See Also:
        Constant Field Values
      • BOM_BUILDER_INTERNAL_PROP

        public static final java.lang.String BOM_BUILDER_INTERNAL_PROP
        See Also:
        Constant Field Values
    • Constructor Detail

      • IlrBOMVocabularyBuilder

        public IlrBOMVocabularyBuilder(java.util.Locale locale)
        This constructor creates an instance of Vocabulary Builder that will be used to populate a Vocabulary from an external Object Model and its associated verbalization.
        Parameters:
        locale - the Locale for which this vocabulary is built.
      • IlrBOMVocabularyBuilder

        public IlrBOMVocabularyBuilder(IlrObjectModel bom,
                               java.util.Locale locale)
        This constructor creates an instance of Vocabulary Builder that will be used to populate a Vocabulary from an external Object Model and its associated verbalization. The vocabulary created by this builder relies to the given Business Object Model.
        Parameters:
        locale - the Locale for which this vocabulary is built.
      • IlrBOMVocabularyBuilder

        public IlrBOMVocabularyBuilder(IlrBOMVocabulary vocabulary)
        This constructor creates an instance of Vocabulary Builder that will be used to populate the provided Vocabulary from an external Object Model and its associated verbalization.
        Parameters:
        vocabulary - the vocabulary to populate
    • Method Detail

      • getVocabulary

        public IlrVocabulary getVocabulary()
        This method returns the vocabulary built by this builder. The returned vocabulary is a composite vocabulary made from a Boot vocabulary that contains all basic types and a User vocabulary populated using the API of this class.
        Returns:
        the vocabulary built by this builder.
      • getUserVocabulary

        public IlrVocabulary getUserVocabulary()
        This method returns the vocabulary filled-in by this builder. The returned vocabulary is not a composite vocabulary and does not contain the Boot vocabulary, but only vocabulary elements created by this builder.
        Returns:
        the vocabulary built by this builder.
      • setResolutionObjectModel

        public void setResolutionObjectModel(IlrObjectModel bom)
        Set the BOM that must be used to resolve missing BOM references encountered when generating the vocabulary
        Parameters:
        bom -
      • setProperties

        public void setProperties(IlrBOMVocabularyBuilder.PropertyMap properties)
        This method set a map of locale-independent and locale-specific properties.
        Parameters:
        properties -
      • createTerm

        public IlrBOMVocabularyBuilder.Term createTerm(java.lang.String label)
        This method creates a Term object from a non-null label. Term specific gender, plural, or articles can be specified using the Term API.
        Parameters:
        label - a non-null label
        Returns:
        a Term object
      • createMethodSignature

        public IlrBOMVocabularyBuilder.MethodSignature createMethodSignature(java.lang.String methodName,
                                                                    java.lang.String returnType,
                                                                    java.util.List<java.lang.String> argumentTypes,
                                                                    IlrBOMVocabularyBuilder.Domain methodDomain,
                                                                    java.util.List<IlrBOMVocabularyBuilder.Domain> argumentDomains,
                                                                    boolean isStatic)
        This method creates a Method object that represents a method of the underlying object model
        Parameters:
        methodName - the name of the method. Must be a Java Identifier.
        returnType - the return type of the method. Refer to the Type Section of the Builder documentation.
        argumentTypes - a list of argument types. Refer to the Type Section of the Builder documentation.
        methodDomain - a Domain associated to the return value of this method. Can be null.
        argumentDomains - a list of domains associated to method arguments. This list must have the same number of elements as argumentTypes. If no domain is associated to an argument, a null value must be put in this list. This list can be null if no domain are set on method arguments.
        isStatic - specifies whether a method is static or not.
        Returns:
        a Method object
      • createMethodSignature

        public IlrBOMVocabularyBuilder.MethodSignature createMethodSignature(java.lang.String methodName,
                                                                    java.lang.String returnType,
                                                                    java.util.List<java.lang.String> argumentTypes,
                                                                    boolean isStatic)
        This method creates a Method object that represents a method of the underlying object model
        Parameters:
        methodName - the name of the method. Must be a Java Identifier.
        returnType - the return type of the method. Refer to the Type Section of the Builder documentation.
        argumentTypes - a list of argument types. Refer to the Type Section of the Builder documentation.
        isStatic - specifies whether a method is static or not.
        Returns:
        a Method object
      • createLiteralDomain

        public IlrBOMVocabularyBuilder.Domain createLiteralDomain(java.util.List<java.lang.String> elements)
        This method creates a LiteralDomain object from the given list of elements. Elements are the string representation of a collection of literal values. This domain is associated to a concept that is associated to a value descriptor.
        Parameters:
        elements - a list of string representation of literal values.
        Returns:
        a LiteralDomain object
      • createEnumDomain

        public IlrBOMVocabularyBuilder.Domain createEnumDomain(java.util.List<java.lang.String> elements)
        This method creates an EnumDomain object from the given list of elements. Elements are ids of Concept Instances if this domain is associated to a concept that is not associated to a value descriptor.
        Parameters:
        elements - a list of concept instance identifiers.
        Returns:
        a Domain object
      • createCollectionDomain

        public IlrBOMVocabularyBuilder.Domain createCollectionDomain(java.lang.String collectionType)
        This method creates a CollectionDomain object from the given collection element type, which is the FQN of the type.
        Parameters:
        collectionType -
        Returns:
        a Domain object
      • createPropertyMap

        public IlrBOMVocabularyBuilder.PropertyMap createPropertyMap(java.util.Map<java.lang.String,java.lang.Object> properties)
        This method creates a PropertyMap from a map of locale-independent properties. This map does not have any locale-specific properties.
        Parameters:
        properties - a map of key,value properties
        Returns:
        an initialized PropertyMap object
      • createPropertyMap

        public IlrBOMVocabularyBuilder.PropertyMap createPropertyMap(java.util.Map<java.lang.String,java.lang.Object> properties,
                                                            java.util.Map<java.lang.String,java.lang.Object> localeProperties)
        This method creates a PropertyMap from a map of locale-independent properties and a locale-specific properties.
        Parameters:
        properties - a map of key,value properties
        localeProperties - a map of key,value properties
        Returns:
        an initialized PropertyMap object
      • addConcept

        public IlrConcept addConcept(java.lang.String id,
                            IlrBOMVocabularyBuilder.Term term,
                            java.util.List<java.lang.String> superConcepts,
                            IlrBOMVocabularyBuilder.Domain domain,
                            IlrBOMVocabularyBuilder.PropertyMap properties)
        This method add a concept to the Vocabulary whose id is 'id' and which is associated to the given term. A set of super-concept id can be specified if this concept does not inherit from object directly.
        Parameters:
        id - the id of the concept. Is the fully-qualified class name of the corresponding class in the Object Model. Must be a qualified Java identifier (examples: 'myClassName', 'myPackage.myClassName').
        term - a term object that associate a verbalization to this concept. If null, a default verbalization will be computed from the class name.
        superConcepts - a list of concept id from which the created concept will derive. This list is made of the class names of the direct super classes of the corresponding class. Class names must be qualified Java identifiers.
        domain - a domain to associate to this concept. Can be null
        properties - a map of properties associated to the created vocabulary element. Can be null.
        Returns:
        the created concept that has been added to the vocabulary
      • addConceptInstance

        public IlrConceptInstance addConceptInstance(java.lang.String classId,
                                            java.lang.String id,
                                            IlrBOMVocabularyBuilder.Term term,
                                            IlrBOMVocabularyBuilder.PropertyMap properties)
        This method add a concept instance to the Vocabulary whose id is 'id' and which is associated to the given term. The concept instance is associated to the concept whose id is 'conceptId'.
        Parameters:
        classId - the id of the class to which this concept instance is related to.
        id - the id of the created concept instance. It is the name of the static final attribute to which this concept instance is associated to in the Object Model. Must be a Java Identifier.
        term - a term object that associate a verbalization to this concept instance. If null, a default verbalization will be computed from the id.
        properties - a map of properties associated to the created vocabulary element. Can be null.
        Returns:
        the created concept instance that has been added to the vocabulary
      • addAttributePhrases

        public IlrSentence[] addAttributePhrases(java.lang.String classId,
                                        java.lang.String attributeId,
                                        java.lang.String attributeType,
                                        IlrBOMVocabularyBuilder.Domain domain,
                                        IlrBOMVocabularyBuilder.PropertyMap properties)
        This method creates a new getter phrase and setter phrase that are associated to a attribute in the underlying Object Model. Generated phrase templates are computed according to the Locale.
        Parameters:
        classId - the id of the class that hold this attribute in the object model.
        attributeId - the attribute name. Must be a Java Identifier.
        attributeType - the type of the attribute.
        domain - the domain that is associated to this attribute. Can be null.
        properties - a map of properties associated to the created phrases. Can be null.
        Returns:
        an array of IlrSentence with the created getter and setter phrases that has been added to the Vocabulary.
      • addAttributeGetterPhrase

        public IlrSentence addAttributeGetterPhrase(java.lang.String classId,
                                           java.lang.String attributeId,
                                           java.lang.String attributeType,
                                           IlrBOMVocabularyBuilder.Term subjectTerm,
                                           java.lang.String phraseTemplate,
                                           IlrBOMVocabularyBuilder.Domain domain,
                                           IlrBOMVocabularyBuilder.PropertyMap properties)
        This method creates a new getter phrase that is associated to a attribute in the underlying Object Model. Note that this method can be called several time to add new phrases associated to the same attribute. The given Phrase Template is a free text that references the attribute holder and subject. {this} refers to the attribute holder. The phrase template also refers to a subject, which represent the attribute value. If used at the beginning of the phrase template the subject can be verbalized according to the context. In the phrase template the subject is referenced as '{the subject label}'.
        Parameters:
        classId - the id of the class that hold this attribute in the object model.
        attributeId - the attribute name. Must be a Java Identifier.
        attributeType - the type of the attribute.
        subjectTerm - the term used as subject. If null, a default one is computed from the attribute name.
        phraseTemplate - the Phrase Template. If null a default template is created.
        domain - the domain that is associated to this attribute. Can be null.
        properties - a map of properties associated to the created phrase. Can be null.
        Returns:
        the created phrase that has been added to the Vocabulary.
      • addAttributeSetterPhrase

        public IlrSentence addAttributeSetterPhrase(java.lang.String classId,
                                           java.lang.String attributeId,
                                           java.lang.String attributeType,
                                           IlrBOMVocabularyBuilder.Term subjectTerm,
                                           java.lang.String phraseTemplate,
                                           IlrBOMVocabularyBuilder.Domain domain,
                                           IlrBOMVocabularyBuilder.PropertyMap properties)
        This method creates a new setter phrase that is associated to a attribute in the underlying Object Model. Note that this method can be called several time to add new phrases associated to the same attribute. The given Phrase Template is a free text that references method holder and arguments using {}. {this} refers to the attribute holder. {0} refers to the value assigned to the attribute. Both {this} and {0} must be referenced by the phrase template.
        Parameters:
        classId - the id of the class that hold this attribute in the object model.
        attributeId - the attribute name. Must be a Java Identifier.
        attributeType - the type of the attribute.
        phraseTemplate - the Phrase Template. If null a default template is created.
        domain - the domain that is associated to this attribute. Can be null.
        properties - a map of properties associated to the created phrase. Can be null.
        Returns:
        the created phrase that has been added to the Vocabulary.
      • addAttributeClearerPhrase

        public IlrSentence addAttributeClearerPhrase(java.lang.String classId,
                                            java.lang.String attributeId,
                                            java.lang.String attributeType,
                                            IlrBOMVocabularyBuilder.Term subjectTerm,
                                            java.lang.String phraseTemplate,
                                            IlrBOMVocabularyBuilder.Domain domain,
                                            IlrBOMVocabularyBuilder.PropertyMap properties)
        This method creates a new clearer phrase that is associated to a attribute in the underlying Object Model. Note that this method can be called several time to add new phrases associated to the same attribute. The given Phrase Template is a free text that references method holder and arguments using {}. {this} refers to the attribute holder. {0} refers to the value assigned to the attribute. Both {this} and {0} must be referenced by the phrase template.
        Parameters:
        classId - the id of the class that hold this attribute in the object model.
        attributeId - the attribute name. Must be a Java Identifier.
        attributeType - the type of the attribute.
        phraseTemplate - the Phrase Template. If null a default template is created.
        domain - the domain that is associated to this attribute. Can be null.
        properties - a map of properties associated to the created phrase. Can be null.
        Returns:
        the created phrase that has been added to the Vocabulary.
      • addMethodPhrase

        public IlrSentence addMethodPhrase(java.lang.String classId,
                                  IlrBOMVocabularyBuilder.MethodSignature method,
                                  java.lang.String phraseTemplate,
                                  IlrBOMVocabularyBuilder.Term subjectTerm,
                                  IlrBOMVocabularyBuilder.PropertyMap properties)
        This method creates a new phrase that is associated to a method in the underlying Object Model. The category of this phrase depends on the method return type: Navigation phrase for a method that returns a non-void value and an Action phrase for void methods. Note that this method can be called several time to add new phrases associated to the same method. The given Phrase Template is a free text that references the method holder and arguments using {}. {this} refers to the method holder. Cannot be used in the phrase template if the underlying method is static. {0} refers to the 1st argument of the method, {1} to the second one etc... If it is a navigation, the phrase template can also refers to a subject, which represent what is returned by this method. If used at the beginning of the phrase template the subject can be verbalized according to the context. In the phrase template the subject is referenced as '{the subject label}'.
        Parameters:
        classId - the id of the class that hold this method in the object model.
        method - a Method object that represent the method of the underlying Object Model.
        phraseTemplate - the Phrase Template. If none is provided, a default one may be computed according to the sentence category determined from the method signature.
        subjectTerm - the term associated to the phrase subject. Its label is referenced as {label} in the phrase template.
        properties - a map of properties associated to the created phrase. Can be null.
        Returns:
        the created phrase that has been added to the Vocabulary.
      • addTerm

        public void addTerm(IlrBOMVocabularyBuilder.Term term)
        Adds the specified term in the glossary if the given term has a specific plural, gender, or article, If the term was already defined in the glossary, it is replaced by the new one.
        Parameters:
        term - The term to add to the glossary
      • getErrorReporter

        public IlrBOMVocabularyBuilder.ErrorReporter getErrorReporter()
        This method return the error reporter currently installed on this builder
        Returns:
        an ErrorReporter object or null if none has been set.
      • setErrorReporter

        public void setErrorReporter(IlrBOMVocabularyBuilder.ErrorReporter errorReporter)
        This method set an error reporter to this builder
        Parameters:
        errorReporter - an error reporter to set
      • addCollectionManipulationMethods

        public void addCollectionManipulationMethods()
        This method adds specific methods to manipulate collection attributes available in the Object Model manipulated by this builder. A collection attribute is an attribute whose type is Array or type is a Java Collection type with a BOM collection domain. The manipulation methods are: a method to add an element in the collection and a method to remove an element from the collection. Created method have the following property: "collectionAttribute" whose value is the fully-qualified name of the corresponding collection attribute. The name of add method is "addTo_" and the name of remove method is "removeFrom_".
      • addCollectionManipulationMethods

        public void addCollectionManipulationMethods(java.lang.String classId,
                                            java.lang.String attributeId)
        This method adds specific methods to manipulate the collection attribute referenced by the given classId and attributeId. See addCollectionManipulationMethods() documentation. This method performs no action if the attribute cannot be found or is not a collection attribute.
        Parameters:
        classId - the fully-qualified name of the class containing the attribute
        attributeId - the name of the collection attribute.
      • addCollectionManipulationMethods

        protected void addCollectionManipulationMethods(IlrClass cl)
      • addCollectionManipulationMethods

        protected void addCollectionManipulationMethods(IlrClass cl,
                                            IlrAttribute a)
      • generateClearMethodName

        protected java.lang.String generateClearMethodName(IlrAttribute collAttr)
      • generateAddToCollectionMethodName

        protected java.lang.String generateAddToCollectionMethodName(IlrAttribute collAttr)
      • generateRemovefromCollectionMethodName

        protected java.lang.String generateRemovefromCollectionMethodName(IlrAttribute collAttr)
      • generateSetCollectionMethodName

        protected java.lang.String generateSetCollectionMethodName(IlrAttribute collAttr)
      • generateBOMVocabulary

        public static IlrVocabulary generateBOMVocabulary(IlrObjectModel bom,
                                          IlrObjectModel resolutionBom,
                                          java.util.Locale locale,
                                          IlrSelector filter)
        This helper method creates a default vocabulary for the given locale for the given business object model. Default locale-specific verbalization rules are applied to create this vocabulary. The resulting vocabulary is a composite vocabulary that includes a Boot vocabulary (including all basic types) and a user vocabulary that is filled-in by reading the content of the given BOM and computing a default verbalization. The default verbalization includes a computed term for all classes of the given object model and a getter and/or a setter phrase for all attributes of these classes, depending on their characteristics (final attributes are not assigned a setter for instance). The class and attributes considered can be controlled through an optional selector given to this method. The selector should implement accepts(IlrClass) and accepts(IlrAttribute) methods to filter out some elements of the given object model. The default verbalization generator is using the following properties, if present, that overrides the default computation:
        • 'verbalization.term' for classes: if assigned to a given class of the object model, the value of this property is used as the default label for the corresponding concept.
        • 'verbalization.subject' for attributes: if assigned to a given attribute, the value of this property is used as the subject term for the getter and setter generated for this attribute.
        Parameters:
        bom - the source object model for which a given vocabulary is computed
        resolutionBom - an optional object model used to look-up missing references if any.
        locale - the Locale for which the vocabulary is computed
        filter - an optional filter to control which element of the given object model should be considered.
        Returns:
        the generated vocabulary that includes both the generated vocabulary and the boot vocabulary.
      • getBOMIdentifier

        public static java.lang.String getBOMIdentifier(java.lang.String id)
        This method returns an id that can be used as BOM class or member identifiers.
        Parameters:
        id - a non-null identifier that may contain whitespaces and other non-compliant characters.
        Returns:
        a BOM-compliant identifier or null if the given id is null or is a zero-length string.

© Copyright IBM Corp. 1987, 2017