net.sourceforge.nite.search
Class Engine

java.lang.Object
  extended by net.sourceforge.nite.search.Engine
All Implemented Interfaces:
Interruptable, Progressable

public class Engine
extends java.lang.Object
implements Interruptable, Progressable

Engine is the main component of NXT (NITE XML Toolkit) Search. The most important methode is search(net.sourceforge.nite.search.SearchableCorpus, java.lang.String) which could be interrupt(). The result, a List of Lists, could be flatten (cf. flattenListOfResults(java.util.List)) or converted into XML (cf. resultToXML(java.util.List)). For debugging the methodes showParseTree(java.lang.String, java.lang.String) and showDNF(java.lang.String) may be useful.


Constructor Summary
Engine()
          Creates a new search engine.
 
Method Summary
 void addProgressListner(ProgressListener listener)
           
static void flattenListOfResults(java.util.List results)
          Converts the result of search(...) into a flat list of lists.
 void interrupt()
          Stops a running search task started by search(...).
 boolean isInterrupted()
          Return true if interrupt() is executed after search(...).
 void removeProgressListner(ProgressListener listener)
           
static java.lang.String resultToXML(java.util.List result)
          Returns a result converted to XML.
static java.lang.String resultToXML(java.util.List result, long max)
          Returns a result converted to XML.
 java.util.List search(SearchableCorpus corpus, java.lang.String query)
          Finds all sets of elements refering to variables satisfing the query.
 java.util.List search(SearchableCorpus corpus, java.lang.String query, long max)
          Finds maximum n sets of elements refering to variables satisfing the query.
 java.lang.String showDNF(java.lang.String query)
          Shows the disjunctive normal form of the query.
 java.lang.String showParseTree(java.lang.String query, java.lang.String prefix)
          Sows the parsing tree of the query.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Engine

public Engine()
Creates a new search engine.

Method Detail

interrupt

public void interrupt()
Stops a running search task started by search(...).

Specified by:
interrupt in interface Interruptable

isInterrupted

public boolean isInterrupted()
Return true if interrupt() is executed after search(...).

Returns:
true if interrupt() is executed after search(...).

search

public java.util.List search(SearchableCorpus corpus,
                             java.lang.String query)
                      throws java.lang.Throwable
Finds all sets of elements refering to variables satisfing the query. For preprocessing the given query string will be parsed by the Parser generated by JavaCC. Afterward all possible sets of elements refering to variables are generated and tested against the query.
The return is a list of lists. The first list contains the variable names. The other lists are sets of elements, ordered like the variable names.
E.g. "($a)($b):..." may return something like { {"$a", "$b"}, {e1 ,e2}, {e1 ,e3}, {e2 ,e4}, ... } where eX are net.sourceforge.nite.nomread.NOMElements. The complex query "($a)($b):... :: ($c): ..." may return something like
  { {"$a", "$b"},
    {e1, e2, {{"$c"}, {e5}, {e6}, ... }},
    {e3, e4, {{"$c"}, {e7}, {e7}, ... }}, ... } .

Parameters:
corpus - the corpus in which will be searched
query - the query string
Returns:
all sets of elements refering to variables satisfing the query
Throws:
java.lang.Throwable - lexical or syntax error of parsing the query or running out of memory

search

public java.util.List search(SearchableCorpus corpus,
                             java.lang.String query,
                             long max)
                      throws java.lang.Throwable
Finds maximum n sets of elements refering to variables satisfing the query. For preprocessing the given query string will be parsed by the Parser generated by JavaCC. Afterward possible sets of elements refering to variables are generated and tested against the query until maximum n sets are found.
The return is a list of lists. The first list contains the variable names. The other lists are sets of elements, ordered like the variable names.
E.g. "($a)($b):..." may return something like { {"$a", "$b"}, {e1 ,e2}, {e1 ,e3}, {e2 ,e4}, ... } where eX are net.sourceforge.nite.nomread.NOMElements. The complex query "($a)($b):... :: ($c): ..." may return something like
  { {"$a", "$b"},
    {e1, e2, {{"$c"}, {e5}, {e6}, ... }},
    {e3, e4, {{"$c"}, {e7}, {e7}, ... }}, ... } .

Parameters:
corpus - the corpus in which will be searched
query - the query string
max - the limit of returning results or if -1 unlimited
Returns:
maximum n sets of elements refering to variables satisfing the query
Throws:
java.lang.Throwable - lexical or syntax error of parsing the query or running out of memory

addProgressListner

public void addProgressListner(ProgressListener listener)
Specified by:
addProgressListner in interface Progressable

removeProgressListner

public void removeProgressListner(ProgressListener listener)
Specified by:
removeProgressListner in interface Progressable

showDNF

public java.lang.String showDNF(java.lang.String query)
                         throws java.lang.Throwable
Shows the disjunctive normal form of the query. For preprocessing the given query, a combination of conditions, will be converted to disjunctive normal form (DNF).

Parameters:
query - the query string
Returns:
how the disjunctive normal form of the query looks
Throws:
java.lang.Throwable - lexical or syntax error of parsing the query

showParseTree

public java.lang.String showParseTree(java.lang.String query,
                                      java.lang.String prefix)
                               throws java.lang.Throwable
Sows the parsing tree of the query. For preprocessing the given query string will be parsed by the Parser generated by JJTree and JavaCC. The result of parsing is a tree which could be shown by this methode.

Parameters:
query - the query string
prefix - every line of return will start with this prefix
Returns:
the parsing tree of the query
Throws:
java.lang.Throwable - lexical or syntax error of parsing the query

flattenListOfResults

public static void flattenListOfResults(java.util.List results)
Converts the result of search(...) into a flat list of lists. The result of a simple query will be unchanged. The result of a complex query will be converted in such a way that it is equale to a simple query.
E.g.: The result {{"$a"}, {e1, {{"$b"}, {e2}, {e3}}}, {e4, {{"$b"}, {e5}}} is converted to {{"$a", "b"}, {e1, e2}, {e1, e3}, {e4, e5}}.

Parameters:
result - the result of search(...)

resultToXML

public static java.lang.String resultToXML(java.util.List result)
Returns a result converted to XML. E.g.: The result {{"$a"}, {e1, {{"$b"}, {e2}, {e3}}}, {e4, {{"$b"}, {e5}}}
is converted to:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<matchlist size="2">
  <match n="1">
  <nite:pointer role="a" xlink:href="file1.xml#e_1"/>
  <matchlist size="2">
    <nite:pointer role="b" xlink:href="file1.xml#e_2"/>
    <nite:pointer role="b" xlink:href="file1.xml#e_3"/>
  </matchlist>
  <nite:pointer role="a" xlink:href="file1.xml#e_4"/>
  <matchlist size="1">
    <nite:pointer role="b" xlink:href="file1.xml#e_5"/>
  </matchlist>
</matchlist>

Parameters:
result - the result of search(...)
Returns:
result converted to XML

resultToXML

public static java.lang.String resultToXML(java.util.List result,
                                           long max)
Returns a result converted to XML. E.g.: The result {{"$a"}, {e1, {{"$b"}, {e2}, {e3}}}, {e4, {{"$b"}, {e5}}}
is converted to:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<matchlist size="2">
  <match n="1">
  <nite:pointer role="a" xlink:href="file1.xml#e_1"/>
  <matchlist size="2">
    <nite:pointer role="b" xlink:href="file1.xml#e_2"/>
    <nite:pointer role="b" xlink:href="file1.xml#e_3"/>
  </matchlist>
  <nite:pointer role="a" xlink:href="file1.xml#e_4"/>
  <matchlist size="1">
    <nite:pointer role="b" xlink:href="file1.xml#e_5"/>
  </matchlist>
</matchlist>

Parameters:
result - the result of search(...)
max - maximum of matches to convert
Returns:
result converted to XML