java.lang.Object
com.pervasive.datarush.analytics.pmml.PMML
Various utility methods for PMML-Dom manipulation
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ElementaddChildElement(Element element, String name) Creates a new child element and adds it to the given element.static ElementaddChildTextElement(Element element, String name, String text) Adds a child element consisting of purely text.static ElementaddExtensionElement(Element element, String name, String value) Adds a PMML Extension element to the specified element.static ElementfindExtensionElement(Element element, String name) Finds a PMML extension element whose name attribute matches that specified or null if not found.static StringfindExtensionValue(Element element, String name) Finds a PMML extension element whose name attribute matches that specified or null if not found.static BigDecimalfindExtensionValueAsBigDecimal(Element element, String name) Finds a PMML extension element whose name attribute matches that specified or null if not found.static DoublefindExtensionValueAsDouble(Element element, String name, Double defaultValue) Finds a PMML extension element whose name attribute matches that specified or null if not found.static StringgetAttribute(Element element, String attrName) Gets the value of the given attribute from the given element.static BigDecimalgetAttributeAsBigDecimal(Element element, String attrName, BigDecimal dflt) Gets the value of the given attribute from the given element as a BigDecimal.static booleangetAttributeAsBoolean(Element element, String attrName, boolean dflt) Gets the value of the given attribute from the given element as a boolean.static doublegetAttributeAsDouble(Element element, String attrName, double dflt) Gets the value of the given attribute from the given element as a double.static <T extends Enum<T>>
TgetAttributeAsEnum(Element element, String attrName, Class<T> enumClass, T dflt) Gets the value of the given attribute from the given element as an enum.static intgetAttributeAsInt(Element element, String attrName, int dflt) Gets the value of the given attribute from the given element as a int.static longgetAttributeAsLong(Element element, String attrName, long dflt) Gets the value of the given attribute from the given element as a long.static BigDecimalgetAttributeAsOptionalBigDecimal(Element element, String attrName) Gets the value of the given attribute from the given element as a BigDecimal.static DoublegetAttributeAsOptionalDouble(Element element, String attrName) Gets the value of the given attribute from the given element as a double.static IntegergetAttributeAsOptionalInt(Element element, String attrName) Gets the value of the given attribute from the given element as a int.static LonggetAttributeAsOptionalLong(Element element, String attrName) Gets the value of the given attribute from the given element as a long.getChildElements(Element element, String... filterTagNames) Returns all of the children elements of the given element.static DocumentgetDocument(Element element) Return the Document associated with the given element.static ElementgetElementByTagName(Element element, String tagName) Returns the single child element of the given tag namegetElementsByTagName(Element element, String tagName) Returns the child elements of the given tag name.static StringgetElementText(Element element) Parses the text from an elementstatic BigDecimalgetElementTextAsBigDecimal(Element element, BigDecimal dflt) Parses the text of the given element as a BigDecimal valuestatic doublegetElementTextAsDouble(Element element, double dflt) Parses the text of the given element as a double valuestatic ElementgetSingleChildElement(Element element) Returns the single child element of the given elementstatic PMMLVersiongetVersion(Document document) Returns the PMML version of the PMML documentstatic DocumentparsePMML(FileClient client, String filePath) Validates the PMML against the latest schema and parsesstatic voidsetAttribute(Element element, String name, double value) Sets the given attribute to the given value.static voidsetAttribute(Element element, String name, long value) Sets the given attribute to the given value.static voidsetAttribute(Element element, String name, Boolean value) Sets the given attribute to the given value if the value is non null.static voidsetAttribute(Element element, String name, Double value) Sets the given attribute to the given value if the value is non null.static voidsetAttribute(Element element, String name, Long value) Sets the given attribute to the given value if the value is non null.static voidsetAttribute(Element element, String name, String value) Sets the given attribute to the given value if the value is non null.static voidsetAttribute(Element element, String name, BigDecimal value) Sets the given attribute to the given value if the value is non null.static <T extends Enum<T>>
voidsetAttribute(Element element, String name, T value) Sets the given attribute to the given value if the value is non null.static voidsetPercentageNumberAttribute(Element element, String name, Double value) Sets the given attribute to the given value if the value is non null.static voidsetProbNumberAttribute(Element element, String name, Double value) Sets the given attribute to the given value if the value is non null.
-
Field Details
-
ELEM_EXTENSION
Constant for theExtensionelement- See Also:
-
ATT_EXTENSION_NAME
Constant for thenameattribute of the extension element.- See Also:
-
ATT_EXTENSION_VALUE
Constant for thevalueattribute of the extension element.- See Also:
-
-
Method Details
-
getDocument
Return the Document associated with the given element.- Parameters:
element- the element- Returns:
- the owning document
-
addChildElement
Creates a new child element and adds it to the given element.- Parameters:
element- The element to add to.name- The name of the element to add.- Returns:
- The child element.
-
getElementsByTagName
Returns the child elements of the given tag name. Note that only immediate children are returned- Parameters:
element- the parent elementtagName- the tag name to search for- Returns:
- the child elements of the given tag name
-
getElementByTagName
Returns the single child element of the given tag name- Parameters:
element- the parent elementtagName- the tag name- Returns:
- the single child element or null if there are non
- Throws:
InvalidPMMLException- if there are multiple children of the given name
-
getChildElements
Returns all of the children elements of the given element. If a set of filter tag names are provided, any nodes with the given names are skipped.- Parameters:
element- the parent elementfilterTagNames- names of nodes to skip (useful for skipping Extension tags)- Returns:
- all of the children elements
-
getSingleChildElement
Returns the single child element of the given element- Parameters:
element- the parent element- Returns:
- the single single element or null if there are no children
- Throws:
InvalidPMMLException- if there is more than one child element
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Type Parameters:
T- the type of the enum- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value if the value is non null.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setProbNumberAttribute
Sets the given attribute to the given value if the value is non null. The number will be formatted as a PMML "PROB-NUMBER".- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setPercentageNumberAttribute
Sets the given attribute to the given value if the value is non null. The number will be formatted as a PMML "PERCENTAGE-NUMBER"- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute. May be null, in which case this call is ignored.
-
setAttribute
Sets the given attribute to the given value.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute.
-
setAttribute
Sets the given attribute to the given value.- Parameters:
element- the element to which the given attribute is being addedname- the name of the attributevalue- the value of the attribute.
-
getAttribute
Gets the value of the given attribute from the given element. Use in preference to element.getAttribute() since this returns null rather than empty string if it doesn't exist.- Parameters:
element- The elementattrName- The name of the attribute.- Returns:
- The attribute value or null if it doesn't exist.
-
getAttributeAsDouble
Gets the value of the given attribute from the given element as a double.- Parameters:
element- The elementattrName- The name of the attribute.dflt- The default value to use if it doesn't exist- Returns:
- The value as a double or dflt if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid double
-
getAttributeAsBigDecimal
public static BigDecimal getAttributeAsBigDecimal(Element element, String attrName, BigDecimal dflt) Gets the value of the given attribute from the given element as a BigDecimal.- Parameters:
element- The elementattrName- The name of the attributedflt- The default value to use if it doesn't exist- Returns:
- The value as a BigDecimal or dflt if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid BigDecimal
-
getAttributeAsInt
Gets the value of the given attribute from the given element as a int.- Parameters:
element- The elementattrName- The name of the attribute.dflt- The default value to use if it doesn't exist- Returns:
- The value as a int or dflt if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid int
-
getAttributeAsLong
Gets the value of the given attribute from the given element as a long.- Parameters:
element- The elementattrName- The name of the attribute.dflt- The default value to use if it doesn't exist- Returns:
- The value as a long or dflt if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid long
-
getAttributeAsBoolean
Gets the value of the given attribute from the given element as a boolean.- Parameters:
element- The elementattrName- The name of the attribute.dflt- The default value to use if it doesn't exist- Returns:
- The value as a boolean or dflt if it doesn't exist.
-
getAttributeAsOptionalDouble
Gets the value of the given attribute from the given element as a double.- Parameters:
element- The elementattrName- The name of the attribute.- Returns:
- The value as a double or null if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid double
-
getAttributeAsOptionalBigDecimal
Gets the value of the given attribute from the given element as a BigDecimal.- Parameters:
element- The elementattrName- The name of the attribute- Returns:
- The value as a BigDecimal or null if it doesn't exist.
-
getAttributeAsOptionalInt
Gets the value of the given attribute from the given element as a int.- Parameters:
element- The elementattrName- The name of the attribute.- Returns:
- The value as a long or null if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid int
-
getAttributeAsOptionalLong
Gets the value of the given attribute from the given element as a long.- Parameters:
element- The elementattrName- The name of the attribute.- Returns:
- The value as a long or null if it doesn't exist.
- Throws:
NumberFormatException- If the given attribute is not a valid long
-
getAttributeAsEnum
public static <T extends Enum<T>> T getAttributeAsEnum(Element element, String attrName, Class<T> enumClass, T dflt) Gets the value of the given attribute from the given element as an enum.- Type Parameters:
T- the type of the enum- Parameters:
element- The elementattrName- The name of the attribute.enumClass- the type of the enumdflt- The default value to use if it doesn't exist- Returns:
- The value as an enum or dflt if it doesn't exist.
- Throws:
IllegalArgumentException- If the given attribute is not a valid value of the enum
-
addChildTextElement
Adds a child element consisting of purely text.- Parameters:
element- the parent elementname- the name of the child elementtext- the text of the child element- Returns:
- a child element
-
getElementText
Parses the text from an element- Parameters:
element- the element- Returns:
- the text of the element or null if the element does not exist. If the element does exist but has empty text, an empty string will be returned.
-
getElementTextAsDouble
Parses the text of the given element as a double value- Parameters:
element- the elementdflt- the default value to return if the element is null- Returns:
- the element text
-
getElementTextAsBigDecimal
Parses the text of the given element as a BigDecimal value- Parameters:
element- the elementdflt- the default value to return if the element is null- Returns:
- the element text
-
addExtensionElement
Adds a PMML Extension element to the specified element.- Parameters:
element- The element to add to.name- The "name" attribute of the extension. May be null.value- The "value" attribute of the extension. May be null.- Returns:
- The Extension element.
-
findExtensionValue
Finds a PMML extension element whose name attribute matches that specified or null if not found.- Parameters:
element- The parent element to search.name- The "name" attribute to match.- Returns:
- The value attribute of the extension.
-
findExtensionValueAsDouble
Finds a PMML extension element whose name attribute matches that specified or null if not found.- Parameters:
element- The parent element to search.name- The "name" attribute to match.defaultValue- Returns this value if the element is not found.- Returns:
- The value attribute of the extension as a double.
-
findExtensionValueAsBigDecimal
Finds a PMML extension element whose name attribute matches that specified or null if not found.- Parameters:
element- The parent element to search.name- The "name" attribute to match.- Returns:
- The value attribute of the extension as a BigDecimal.
-
findExtensionElement
Finds a PMML extension element whose name attribute matches that specified or null if not found.- Parameters:
element- The parent element to search.name- The "name" attribute to match.- Returns:
- The PMML extension element or null if not found.
-
getVersion
Returns the PMML version of the PMML document- Parameters:
document- the PMML document- Returns:
- the PMML version
-
parsePMML
Validates the PMML against the latest schema and parses- Parameters:
client- the file clientfilePath- the path to the file- Returns:
- the PMML document
-