search
index
/home/max/LRApy/search.py

Project: LRApy
Author: Max Jakob (max.jakob@web.de)
Module: search
Module Description: This module contains the SearchEngine class for
context searching in the corpus and a function to compute patterns
from a phrase list.
 
Version: 1.1
Last change: 2007-02-15
 
Copyright 2007 by Max Jakob.
This code is released under the GNU GPL. See the accompanying LICENSE file.
 
Embedded documentation can be translated with the Python pydoc module.

 
Modules
       
corpusInterface
os
re

 
Classes
       
SearchEngine

 
class SearchEngine
    This class provides specific search funtionalities for the LRA
system. That involves methods to count word pairs in a certain scope,
to search for phrases in a certain scope (with a minimum and a maximum
of intervening words), and to count pattern matchings in phrases that
were found before (caching).
 
The class uses the CorpusInterface of the corpus module to perform
context search operations.
 
  Methods defined here:
__init__(self, directory)
cacheInterPhrases(self, word1, word2, minInter, maxInter)
Caches a list of phrases, that intervene between two words.
The phrase length must be at least <minInter>, and must not be
bigger than <maxInter>. The occurrence order of the two words is
irrelevant.     Suffixes are ignored when searching for the words.
countPatternForWordPair(self, pattern, word1, word2)
Returns the number of matches of <pattern> in the the corpus for
<word1> <pattern> <word2>.
<pattern> is a string containing words or wildcards for words ("*")
that are split by whitespace.
The pairPhraseDict is used to count the patterns, thus the method
cacheInterPhrases must be called before using this method.
countWordPairInScope(self, word1, word2, scope)
Returns the number of occurrences of two words in a certain scope,
while saving the intervening phrases in the cache.
getCachedPhrases(self)
Returns all intervening phrases of all word pairs previously
searched for.
The pairPhraseDict is used to get the phrases, thus the method
cacheInterPhrases must be called before using this method.
getCachedPhrasesForWordPair(self, word1, word2)
Returns all intervening phrases of a word pair in given and
flipped order.
The pairPhraseDict is used to get the phrases, thus the method
cacheInterPhrases must be called before using this method.

 
Functions
       
getPatterns(phraseList, numPatterns)
Returns a list of patterns. <phraseList> is a list of lists.
The lists inside, contain words and form a phrase together.
A pattern is recursively constructed by replacing any or all or none
of those words with a wildcard ("*"):
  Example (phraseList=[["it"], ["works", "well"]]):
  ["it", "*", "works well", "works *", "* well", "* *"]
 
Only the <numPatterns> most frequent patterns are kept.