Modifier and Type | Field and Description |
---|---|
protected static MatchXml |
compareMeta
Compare xml elements for similarity
|
protected static java.util.HashMap<java.lang.String,org.licas_xml.abs.Element> |
definedStructures
Stores pre-defined structures
|
protected org.ai_heuristic.def.EvaluateMathDef |
mathEngine
For evaluating more mathematical expressions
|
protected PatternQueryEngine |
patternQueryEngine
Query engine that uses pattern matching to search over metadata
|
protected static org.licas_xml.abs.Element |
simpleStructure
A default xml structure for a simple source type
|
protected TextLinesEngine |
textLinesEngine
Query engine to make general comparisons over text lines of any type
|
Constructor and Description |
---|
QueryMediator()
Create a new instance of QueryMediator.
|
Modifier and Type | Method and Description |
---|---|
static float |
compareMetadata(org.licas_xml.abs.Element compareWith,
org.licas_xml.abs.Element metaStructure,
java.lang.String matchType)
Compare the metadata as XML structure and return the result.
|
org.licas_xml.abs.Element |
executeQuery(org.licas_xml.abs.Element theQuery,
java.lang.Object source)
Executes either an information text or XML-based query.
|
java.lang.Object |
executeQuery(org.licas_xml.abs.Element theQuery,
java.lang.Object source1,
java.lang.Object source2)
Executes an information text or XML-based query, or a mathematical operation.
|
protected java.lang.Object |
executeQuery1(QueryModel queryModel,
java.lang.Object source1,
java.lang.Object source2)
Executes an information text or XML-based query, or a mathematical operation.
|
protected org.licas_xml.abs.Element |
executeQuery2(QueryModel queryModel,
java.lang.Object source)
Executes either an information text or XML-based query.
|
protected org.licas_xml.abs.Element |
executeQueryModel(QueryModel queryModel,
java.lang.Object source)
Executes either an information text or XML-based query.
|
protected java.lang.Object |
executeQueryModel(QueryModel queryModel,
java.lang.Object source1,
java.lang.Object source2)
Executes an information text or XML-based query, or a mathematical operation.
|
java.util.ArrayList<java.lang.Integer> |
findLinesContain(java.util.ArrayList<java.lang.String> allLines,
PatternConstraint valueConstraint,
java.util.ArrayList<java.lang.Integer> currentIndexes)
Find only the lines that contain any of the words in the list of common
words in any sort of word sequence in the line.
|
protected java.util.ArrayList<java.lang.Integer> |
findLinesContain1(java.util.ArrayList<java.lang.String> allLines,
PatternConstraint valueConstraint,
java.util.ArrayList<java.lang.Integer> currentIndexes)
Find only the lines that contain any of the words in the list of common
words in any sort of word sequence in the line.
|
static org.licas_xml.abs.Element |
getQueryStructure(java.lang.String structureType)
Retrieve a defined structure from its name.
|
org.licas_xml.abs.Element |
getStats()
This would normally return some query stat values, but the default query engine
does not process any stats.
|
static org.licas_xml.abs.Element |
getStructurePart(java.util.ArrayList<java.lang.String> keywords,
org.licas_xml.abs.Element origStructure)
Get the structure part relating to the entered keywords.
|
protected static org.licas_xml.abs.Element |
getStructurePart(int index,
java.util.ArrayList<java.lang.String> keywords,
org.licas_xml.abs.Element origStructure)
Get the structure part relating to the entered keywords.
|
static boolean |
isAnyNode(java.lang.String theValue)
Return true if the comparison indicates any node.
|
static boolean |
isAnyValue(java.lang.String theValue)
Return true if the comparison indicates any value.
|
static boolean |
isExactNode(java.lang.String theValue)
Return true if the comparison indicates exact node.
|
static boolean |
isKeyWord(java.lang.String theKeyWord)
Return true if the string entered is a recognised keyword.
|
static boolean |
isSubTree(java.lang.String theValue)
Return true if the value indicates a sub-tree node search.
|
static boolean |
isValueCount(java.lang.String theValue)
Return true if the value indicates a sub-tree node search.
|
static org.licas_xml.abs.Element |
listToElement(java.util.ArrayList<org.licas_xml.abs.Element> replyList)
Nest the list of xml elements inside a query reply element.
|
<T> org.licas_xml.abs.Element |
mathCompare(java.lang.String valueType,
T value1,
T value2,
java.lang.String operator)
Evaluate the comparison expression.
|
<T> java.lang.Object |
mathOperation(java.lang.String valueType,
T value1,
T value2,
java.lang.String operator)
Evaluate the mathematical expression.
|
static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
parseToLists(java.util.HashMap<java.lang.String,java.lang.Object> allTexts)
Convert any string-based representation into a list of lines.
|
java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> |
processTextQuery(java.util.HashMap<java.lang.String,java.lang.Object> allTexts,
java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> allIndexes,
QueryModelText queryModel)
Find only the lines that match the text comparison.
|
java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> |
processTextQuery(java.lang.String theText,
java.util.ArrayList<java.lang.Integer> currentIndexes,
QueryModelText queryModel)
Find only the lines that match the text comparison.
|
protected java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> |
processTextQuery1(java.lang.String theText,
java.util.ArrayList<java.lang.Integer> currentIndexes,
QueryModelText queryModel)
Find only the lines that match the text comparison.
|
protected java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> |
processTextQuery2(java.util.HashMap<java.lang.String,java.lang.Object> allTexts,
java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> allIndexes,
QueryModelText queryModel)
Find only the lines that match the text comparison.
|
java.util.ArrayList<org.licas_xml.abs.Element> |
processXmlQuery(org.licas_xml.abs.Element textToSearch,
QueryModelXml queryModel)
Query the xml-based text to find matching information.
|
protected java.util.ArrayList<java.util.ArrayList<org.licas_xml.abs.Element>> |
processXmlQuery1(org.licas_xml.abs.Element textToSearch,
QueryModelXml queryModel)
Query the xml-based text to find matching information.
|
void |
setEvaluateMath(org.ai_heuristic.def.EvaluateMathDef thisEvalMath)
Set the mathematical evaluator.
|
protected int |
singleCondition(QueryModel queryModel,
java.lang.Object source)
Check if the query represents a single condition that can be met through some
general check.
|
protected static org.licas_xml.abs.Element simpleStructure
protected static java.util.HashMap<java.lang.String,org.licas_xml.abs.Element> definedStructures
protected org.ai_heuristic.def.EvaluateMathDef mathEngine
protected TextLinesEngine textLinesEngine
protected PatternQueryEngine patternQueryEngine
protected static MatchXml compareMeta
public QueryMediator() throws java.lang.Exception
java.lang.Exception
- any error.public static boolean isValueCount(java.lang.String theValue)
theValue
- the value.public static boolean isKeyWord(java.lang.String theKeyWord)
theKeyWord
- the keyword to check.public static boolean isSubTree(java.lang.String theValue)
theValue
- the value.public static boolean isExactNode(java.lang.String theValue)
theValue
- the value.public static boolean isAnyNode(java.lang.String theValue)
theValue
- the value.public static boolean isAnyValue(java.lang.String theValue)
theValue
- the value.public java.lang.Object executeQuery(org.licas_xml.abs.Element theQuery, java.lang.Object source1, java.lang.Object source2) throws java.lang.Exception
theQuery
- the query specification. This must be the associated QueryModel
type.source1
- the first source content. String for the text query engine, or XML-based
for the pattern query engine, or arbitrary object for the mathematical evaluator.source2
- the second source content. An arbitrary object for the mathematical
evaluator, or null for a text or XML-based query over the first source. Note that
the query model queryType
must also be QueryConst
.ASMATHCOMPARE
or ASMATHEVAL
for a mathematical operation to be recognised.java.lang.Exception
- any error.protected java.lang.Object executeQueryModel(QueryModel queryModel, java.lang.Object source1, java.lang.Object source2) throws java.lang.Exception
queryModel
- the query specification.source1
- the first source content. String for the text query engine, or XML-based
for the pattern query engine, or arbitrary object for the mathematical evaluator.source2
- the second source content. An arbitrary object for the mathematical
evaluator, or null for a text or XML-based query over the first source. Note that
the query model queryType
must also be QueryConst
.ASMATHCOMPARE
or ASMATHEVAL
for a mathematical operation to be recognised.java.lang.Exception
- any error.public org.licas_xml.abs.Element executeQuery(org.licas_xml.abs.Element theQuery, java.lang.Object source) throws java.lang.Exception
executeQuery
in interface QueryDef
theQuery
- the query specification. This must be the associated QueryModel
type.source
- the source content. String for the text query engine, or XML-based
for the pattern query engine.java.lang.Exception
- any error.protected org.licas_xml.abs.Element executeQueryModel(QueryModel queryModel, java.lang.Object source) throws java.lang.Exception
queryModel
- the query specification.source
- the source content. String for the text query engine, or XML-based
for the pattern query engine.java.lang.Exception
- any error.public java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> processTextQuery(java.lang.String theText, java.util.ArrayList<java.lang.Integer> currentIndexes, QueryModelText queryModel) throws java.lang.Exception
theText
- the text to process.currentIndexes
- the list of current indexes to search from.queryModel
- the query to process.java.lang.Exception
- any error.public java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> processTextQuery(java.util.HashMap<java.lang.String,java.lang.Object> allTexts, java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> allIndexes, QueryModelText queryModel) throws java.lang.Exception
allTexts
- the text to process. This is a keyed list of different text
parts that each constraint can evaluate separately. A single text document
can equally be included.allIndexes
- the list of current indexes to search from. This is a
keyed list valid line indexes for each of the text parts or documents.queryModel
- the query to process.java.lang.Exception
- any error.public java.util.ArrayList<org.licas_xml.abs.Element> processXmlQuery(org.licas_xml.abs.Element textToSearch, QueryModelXml queryModel) throws java.lang.Exception
textToSearch
- the xml-based text to search over.queryModel
- the query model.java.lang.Exception
- any error.public java.util.ArrayList<java.lang.Integer> findLinesContain(java.util.ArrayList<java.lang.String> allLines, PatternConstraint valueConstraint, java.util.ArrayList<java.lang.Integer> currentIndexes) throws java.lang.Exception
allLines
- the lines of text to process.valueConstraint
- the constraint to satisfy.currentIndexes
- the list of current indexes to search from.java.lang.Exception
- any error.public <T> org.licas_xml.abs.Element mathCompare(java.lang.String valueType, T value1, T value2, java.lang.String operator) throws java.lang.Exception
T
- generic value type.valueType
- the type of the value. This is the object type class name.value1
- first value.value2
- second value.operator
- comparison operator, which evaluates 'value1 operator value2'.
Operator can be greater than (GT), less than (LT), etc. These are all defined in
the AiHeuristicConst
class.QueryConst
.OK
element if true, or NOTOK
element if false.
This allows for a metadata match.java.lang.Exception
- any error.public <T> java.lang.Object mathOperation(java.lang.String valueType, T value1, T value2, java.lang.String operator) throws java.lang.Exception
T
- generic value type.valueType
- the type of the value. This is the object type class name.value1
- first value.value2
- second value.operator
- mathematical operator - can be add, subtract, multiply, divide.
These are all defined in the AiHeuristicConst
class.java.lang.Exception
- any error.public org.licas_xml.abs.Element getStats() throws java.lang.Exception
protected java.lang.Object executeQuery1(QueryModel queryModel, java.lang.Object source1, java.lang.Object source2) throws java.lang.Exception
queryModel
- the query specification.source1
- the first source content. String for the text query engine, or XML-based
for the pattern query engine, or arbitrary object for the mathematical evaluator.source2
- the second source content. An arbitrary object for the mathematical
evaluator, or null for a text or XML-based query over the first source. Note that
the query model queryType
must also be QueryConst
.ASMATHCOMPARE
or ASMATHEVAL
for a mathematical operation to be recognised.java.lang.Exception
- any error.protected org.licas_xml.abs.Element executeQuery2(QueryModel queryModel, java.lang.Object source) throws java.lang.Exception
queryModel
- the query specification.source
- the source content. String for the text query engine, or XML-based
for the pattern query engine.java.lang.Exception
- any error.protected java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> processTextQuery1(java.lang.String theText, java.util.ArrayList<java.lang.Integer> currentIndexes, QueryModelText queryModel) throws java.lang.Exception
theText
- the text to process.currentIndexes
- the list of current indexes to search from.queryModel
- the query to process.java.lang.Exception
- any error.protected java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> processTextQuery2(java.util.HashMap<java.lang.String,java.lang.Object> allTexts, java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.Integer>> allIndexes, QueryModelText queryModel) throws java.lang.Exception
allTexts
- the text to process. This is a keyed list of different text
parts that each constraint can evaluate separately. A single text document
can equally be included.allIndexes
- the list of current indexes to search from. This is a
keyed list valid line indexes for each of the text parts or documents.queryModel
- the query to process.java.lang.Exception
- any error.protected java.util.ArrayList<java.util.ArrayList<org.licas_xml.abs.Element>> processXmlQuery1(org.licas_xml.abs.Element textToSearch, QueryModelXml queryModel) throws java.lang.Exception
textToSearch
- the xml-based text to search over.queryModel
- the query model.java.lang.Exception
- any error.protected int singleCondition(QueryModel queryModel, java.lang.Object source)
queryModel
- the query description.source
- the source to query.protected java.util.ArrayList<java.lang.Integer> findLinesContain1(java.util.ArrayList<java.lang.String> allLines, PatternConstraint valueConstraint, java.util.ArrayList<java.lang.Integer> currentIndexes)
allLines
- the lines of text to process.valueConstraint
- the constraint to satisfy.currentIndexes
- the list of current indexes to search from.public static float compareMetadata(org.licas_xml.abs.Element compareWith, org.licas_xml.abs.Element metaStructure, java.lang.String matchType) throws java.lang.Exception
MetaConst
.ANYSTRUCTURE
: always returns 1.0.MetaConst
.ALLPARTIAL
: both element name and value must be present but the exact
structure is not required. Returns 1.0 for a full match or 0.5 if values or parts
of values are missing.MetaConst
.ALLEXACT
: both element name and value must be present and the exact
structure is also required. Returns 1.0 for a full match or 0.5 if values or parts
of values are missing.MetaConst
.VALUESPARTIAL
: only the value must be present but the exact structure
is not required. Returns 1.0 for a full match or 0.5 if values or parts of values
are missing.MetaConst
.VALUESEXACT
: only the value must be present and the exact structure
is also required. Returns 1.0 for a full match or 0.5 if values or parts of values
are missing.compareWith
- the metadata of the service to compare with.metaStructure
- the metadata that defines the desired structure.matchType
- the type of matching process. If null, then MetaConst
.ALLEXACT
is used.java.lang.Exception
- any error.public static org.licas_xml.abs.Element getQueryStructure(java.lang.String structureType)
structureType
- the name of the structure.public static org.licas_xml.abs.Element getStructurePart(java.util.ArrayList<java.lang.String> keywords, org.licas_xml.abs.Element origStructure)
keywords
- the keyword list to include in the structure.origStructure
- the original structure definition.protected static org.licas_xml.abs.Element getStructurePart(int index, java.util.ArrayList<java.lang.String> keywords, org.licas_xml.abs.Element origStructure)
index
- index for next keyword.keywords
- the keyword list to include in the structure.origStructure
- the original structure definition.public void setEvaluateMath(org.ai_heuristic.def.EvaluateMathDef thisEvalMath)
thisEvalMath
- the mathematical evaluator.public static org.licas_xml.abs.Element listToElement(java.util.ArrayList<org.licas_xml.abs.Element> replyList)
replyList
- the list of elements to nest.public static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> parseToLists(java.util.HashMap<java.lang.String,java.lang.Object> allTexts)
allTexts
- a list of all texts to convert.