java.lang.Object
org.apache.jena.reasoner.rulesys.Util
A small random collection of utility functions used by the rule systems.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleancheckBinaryPredicate(Property predicate, Resource configuration) Helper method - extracts the truth of a boolean configuration predicate.static booleancomparable(Node n1, Node n2) Test if two literals are comparable by an order operator (both numbers or both times)static intcompareInstants(Node n1, Node n2) Compare two time Instant nodes.static intcompareNumbers(Node n1, Node n2) Compare two numeric nodes.static intcompareTypedLiterals(Node n1, Node n2) General order comparator for typed literal nodes, works for all numbers and for date times.static booleanconvertBooleanPredicateArg(Property parameter, Object value) Convert the value of a boolean configuration parameter to a boolean value.static intconvertIntegerPredicateArg(Property parameter, Object value) Convert the value of an integer configuration parameter to an int value.convertList(Node root, RuleContext context) Convert an (assumed well formed) RDF list to a java list of Nodesstatic IntegergetIntegerPredicate(Property predicate, Resource configuration) Helper method - extracts the value of an integer configuration predicate.static intgetIntValue(Node n) Return the integer value of a literal nodestatic NodegetPropValue(Node root, Node prop, Graph context) Helper - returns the (singleton) value for the given property on the given root node in the data graph.static NodegetPropValue(Node root, Node prop, Finder context) Helper - returns the (singleton) value for the given property on the given root node in the data graph.static NodegetPropValue(Node root, Node prop, RuleContext context) Helper - returns the (singleton) value for the given property on the given root node in the data graph.static booleanCheck whether a Node is an Instant (DateTime) valuestatic booleanCheck whether a Node is a numeric (integer) valuestatic Rule.ParserloadRuleParserFromResourceFile(String filename) Open a resource file and read it all into a single string.static StringloadURLFile(String urlStr) Open a file defined by a URL and read all of it into a single string.static NodemakeDoubleNode(double value) Construct a new double valued nodestatic NodemakeIntNode(int value) Construct a new integer valued nodestatic NodeConstruct an RDF list from the given array of nodes and assert it in the graph returning the head of the list.static NodemakeLongNode(long value) Construct a new long valued nodestatic voidupdateParameter(Resource config, Property parameter, Object value) Replace the value for a given parameter on the resource by a new value.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
isNumeric
Check whether a Node is a numeric (integer) value -
getIntValue
Return the integer value of a literal node -
isInstant
Check whether a Node is an Instant (DateTime) value -
comparable
Test if two literals are comparable by an order operator (both numbers or both times) -
compareNumbers
Compare two numeric nodes.- Parameters:
n1- the first numeric valued literal noden2- the second numeric valued literal node- Returns:
- -1 if n1 is less than n2, 0 if n1 equals n2 and +1 if n1 greater than n2
- Throws:
ClassCastException- if either node is not numeric
-
compareInstants
Compare two time Instant nodes.- Parameters:
n1- the first time instant (XSDDateTime) valued literal noden2- the second time instant (XSDDateTime) valued literal node- Returns:
- -1 if n1 is less than n2, 0 if n1 equals n2 and +1 if n1 greater than n2
- Throws:
ClassCastException- if either not is not numeric
-
compareTypedLiterals
General order comparator for typed literal nodes, works for all numbers and for date times. -
getPropValue
Helper - returns the (singleton) value for the given property on the given root node in the data graph. -
getPropValue
Helper - returns the (singleton) value for the given property on the given root node in the data graph. -
getPropValue
Helper - returns the (singleton) value for the given property on the given root node in the data graph. -
convertList
Convert an (assumed well formed) RDF list to a java list of Nodes- Parameters:
root- the root node of the listcontext- the graph containing the list assertions
-
makeIntNode
Construct a new integer valued node -
makeLongNode
Construct a new long valued node -
makeDoubleNode
Construct a new double valued node -
makeList
Construct an RDF list from the given array of nodes and assert it in the graph returning the head of the list. -
loadRuleParserFromResourceFile
Open a resource file and read it all into a single string. Treats lines starting with # as comment lines, as per stringFromReader -
loadURLFile
Open a file defined by a URL and read all of it into a single string. If the URL fails it will try a plain file name as well.- Throws:
IOException
-
checkBinaryPredicate
Helper method - extracts the truth of a boolean configuration predicate.- Parameters:
predicate- the predicate to be testedconfiguration- the configuration node- Returns:
- null if there is no setting otherwise a Boolean giving the setting value
-
getIntegerPredicate
Helper method - extracts the value of an integer configuration predicate.- Parameters:
predicate- the predicate to be testedconfiguration- the configuration node- Returns:
- null if there is no such configuration parameter otherwise the value as an integer
-
convertBooleanPredicateArg
Convert the value of a boolean configuration parameter to a boolean value. Allows the value to be specified using a String or Boolean.- Parameters:
parameter- the configuration property being set (to help with error messages)value- the parameter value- Returns:
- the converted value
- Throws:
IllegalParameterException- if the value can't be converted
-
convertIntegerPredicateArg
Convert the value of an integer configuration parameter to an int value. Allows the value to be specified using a String or Number.- Parameters:
parameter- the configuration property being set (to help with error messages)value- the parameter value- Returns:
- the converted value
- Throws:
IllegalParameterException- if the value can't be converted
-
updateParameter
Replace the value for a given parameter on the resource by a new value.- Parameters:
config- the resource whose values are to be updatedparameter- a predicate defining the parameter to be setvalue- the new value
-