Class OneQuerySearch
- java.lang.Object
-
- java.lang.Thread
-
- nzilbb.labbcat.server.task.Task
-
- nzilbb.labbcat.server.search.SearchTask
-
- nzilbb.labbcat.server.db.OneQuerySearch
-
- All Implemented Interfaces:
Runnable
,nzilbb.util.MonitorableTask
public class OneQuerySearch extends SearchTask
Implementation of search that uses a single monolithic SQL query to identify matches.- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description OneQuerySearch()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Override to allow update-statement cancellationString
generateOneSpanSql(Vector<Object> parameters, nzilbb.ag.Schema schema, nzilbb.ag.Layer spanLayer, LayerMatch layerMatch)
Create an SQL query that identifies results that match the search matrix patterns, optimised for a matrix that only searches one span layer, filling in the given lists with information about parameters to set.String
generateOrthographySql(Vector<Object> parameters, nzilbb.ag.Schema schema)
Create an SQL query that identifies results that match the search matrix patterns, optimised for a matrix that only searches the orthography layer, filling in the given lists with information about parameters to set.String
generateSql(Vector<Object> parameters, nzilbb.ag.Schema schema, Predicate<nzilbb.ag.Layer> layerIsSpanningAndWordAnchored, UnaryOperator<String> participantCondition, UnaryOperator<String> transcriptCondition)
Create an SQL query that identifies results that match the search matrix patterns, filling in the given lists with information about parameters to set.static boolean
IsPhraseLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'phrase' layer.static boolean
IsSegmentLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'segment' layer.static boolean
IsSpanLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'span' layer.static boolean
IsWordLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'word' layer.void
keepAlive()
Somebody is still interested in the thread, so keep it from dying.-
Methods inherited from class nzilbb.labbcat.server.search.SearchTask
getAnchorConfidenceThreshold, getDescription, getMainParticipantOnly, getMatchesPerTranscript, getMatrix, getMaxMatches, getOverlapThreshold, getRestrictByUser, getResults, getSuppressResults, getWordsContext, run, setAnchorConfidenceThreshold, setDescription, setMainParticipantOnly, setMatchesPerTranscript, setMatrix, setMaxMatches, setOverlapThreshold, setRestrictByUser, setResults, setSuppressResults, setWordsContext, validate
-
Methods inherited from class nzilbb.labbcat.server.task.Task
defaultThreadName, findTask, findTask, getCreationTime, getDuration, getLastException, getLastKeepAlive, getLog, getMaxLogSize, getPercentComplete, getResources, getResultTarget, getResultText, getResultUrl, getRunning, getStatus, getStore, getStoreCache, getTaskThreadGroup, getWaitToDieMilliseconds, getWho, release, setLastException, setLastKeepAlive, setMaxLogSize, setResources, setResultTarget, setResultText, setResultUrl, setStatus, setStore, setStoreCache, setWaitToDieMilliseconds, setWho, waitToDie, waitToDie
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
generateSql
public String generateSql(Vector<Object> parameters, nzilbb.ag.Schema schema, Predicate<nzilbb.ag.Layer> layerIsSpanningAndWordAnchored, UnaryOperator<String> participantCondition, UnaryOperator<String> transcriptCondition) throws Exception
Create an SQL query that identifies results that match the search matrix patterns, filling in the given lists with information about parameters to set.- Parameters:
parameters
- List of parameter values, which must be Double, Integer, or String.schema
- The layer schema.layerIsSpanningAndWordAnchored
- A predicate that determines whether the given layer is a phrase or span layer for which all annotations share anchors with words.participantCondition
- Supplies the WHERE condition that identifies the target participants, presumably based onMatrix.participantQuery
.transcriptCondition
- Supplies the WHERE condition that identifies the target transcripts, presumably based onMatrix.transcriptQuery
.- Returns:
- An SQL query to implement the query.
- Throws:
Exception
- If the search should be halted for any reason - e.g. theMatrix.participantQuery
identifies no participants.
-
generateOrthographySql
public String generateOrthographySql(Vector<Object> parameters, nzilbb.ag.Schema schema) throws Exception
Create an SQL query that identifies results that match the search matrix patterns, optimised for a matrix that only searches the orthography layer, filling in the given lists with information about parameters to set.This implementation makes speed gains over
generateSql(java.util.Vector<java.lang.Object>, nzilbb.ag.Schema, java.util.function.Predicate<nzilbb.ag.Layer>, java.util.function.UnaryOperator<java.lang.String>, java.util.function.UnaryOperator<java.lang.String>)
by supporting only the orthography layer, and no border conditions, main-participant or transcript-type filtering. Allowing only plain, full-database searches of the orthography layer means that the initial search query can be completed with no SQL JOINs, meaning that searches can complete in something like one sixth of the time, on very large databases.- Parameters:
parameters
- List of parameter values, which must be Double, Integer, or String.schema
- The layer schema.- Returns:
- An SQL query to implement the query.
- Throws:
Exception
- If the search should be halted for any reason - e.g. theMatrix.participantQuery
identifies no participants.
-
generateOneSpanSql
public String generateOneSpanSql(Vector<Object> parameters, nzilbb.ag.Schema schema, nzilbb.ag.Layer spanLayer, LayerMatch layerMatch) throws Exception
Create an SQL query that identifies results that match the search matrix patterns, optimised for a matrix that only searches one span layer, filling in the given lists with information about parameters to set.This implementation makes speed gains over
generateSql(java.util.Vector<java.lang.Object>, nzilbb.ag.Schema, java.util.function.Predicate<nzilbb.ag.Layer>, java.util.function.UnaryOperator<java.lang.String>, java.util.function.UnaryOperator<java.lang.String>)
by supporting only a single span (freeform) layer, identifying the matching spans first, and then identifying the first word in each to provide the match token.- Parameters:
parameters
- List of parameter values, which must be Double, Integer, or String.schema
- The layer schema.spanLayer
- The one span layer being searched.layerMatch
- The one span's match condition.- Returns:
- An SQL query to implement the query.
- Throws:
Exception
- If the search should be halted for any reason - e.g. theMatrix.participantQuery
identifies no participants.
-
keepAlive
public void keepAlive()
Somebody is still interested in the thread, so keep it from dying.
-
cancel
public void cancel()
Override to allow update-statement cancellation
-
IsSegmentLayer
public static boolean IsSegmentLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'segment' layer.- Parameters:
layer
- The layer to test.schema
- The schema the layer comes from.- Returns:
- true if the given layer is the "segment" layer or a child of it.
-
IsWordLayer
public static boolean IsWordLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'word' layer.- Parameters:
layer
- The layer to test.schema
- The schema the layer comes from.- Returns:
- true if the given layer is the word layer or a child of it.
-
IsPhraseLayer
public static boolean IsPhraseLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'phrase' layer.- Parameters:
layer
- The layer to test.schema
- The schema the layer comes from.- Returns:
- true if the given layer is the turn layer or a non-word child of it.
-
IsSpanLayer
public static boolean IsSpanLayer(nzilbb.ag.Layer layer, nzilbb.ag.Schema schema)
Determines whether the given layer is a 'span' layer.- Parameters:
layer
- The layer to test.schema
- The schema the layer comes from.- Returns:
- true if the given layer is an aligned top-level layer - i.e. parent is root.
-
-