예제 #1
0
파일: QueryProcessor.cs 프로젝트: mo5h/omeo
 private static void PushTermOnStack(string term, TermIndexAccessor index, Stack opStack)
 {
     if (!FullTextIndexer.isValuableToken(term))
     {
         opStack.Push(new StopwordTerm());
         if (Stopwords.IndexOf(term) == -1)
         {
             Stopwords.Add(term);
         }
     }
     else
     {
         TermIndexRecord record = index.GetRecord(term);
         if (record != null)
         {
             int order = Lexemes.IndexOf(term);
             if (order == -1)
             {
                 Lexemes.Add(term);
                 order = Lexemes.Count - 1;
             }
             record.PopulateRecordID((ushort)order);
         }
         opStack.Push(record);
     }
 }
예제 #2
0
 private void LoadTermIndex()
 {
     Trace.WriteLineIf(!_suppTrace, "-- FullTextIndexer -- Started creating Accessor over [" + OMEnv.TermIndexFileName + "]");
     _termsAccessor = new TermIndexAccessor(OMEnv.TermIndexFileName);
     _termsAccessor.Load();
     Trace.WriteLineIf(!_suppTrace, "-- FullTextIndexer -- TermIndexAccessor loaded " + _termsAccessor.TermsNumber + " terms");
 }
예제 #3
0
 public static void  FlushDocument(TermIndexAccessor termIndex, int docId, int maxTermInDoc, IntHashTable tokens)
 {
     foreach (IntHashTable.Entry e in tokens)
     {
         try
         {
             termIndex.AddRecord(docId, e.Key, e.Value, maxTermInDoc);
         }
         catch (Exception exc)
         {
             Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- IndexConstructor -- Flushing document -- exception occured with key " + e.Key);
             throw new FormatException("-- IndexConstructor -- Flushing document -- exception occured with key " + e.Key, exc);
         }
     }
 }
예제 #4
0
파일: QueryProcessor.cs 프로젝트: mo5h/omeo
        public static Entry[]  ProcessQuery(QueryPostfixForm postfixForm, TermIndexAccessor termIndex, bool appendIdMappings)
        {
            Stack opStack = new Stack();

            Entry[] result = null;
            Error = ErrorStatus.NoError;
            MappedInstances.Clear();

            if (!appendIdMappings)
            {
                Lexemes.Clear();
                Stopwords.Clear();
            }

            try
            {
                IteratePostfixExpression(postfixForm, termIndex, opStack);

                //-----------------------------------------------------------------
                //  Now only one Entry[] must remain on the top of the stack. It may
                //  be null if no document correspond to the query
                //-----------------------------------------------------------------
                if (opStack.Count != 1)
                {
                    throw new ApplicationException("QueryParser -- Illegal query statement found");
                }

                if (!(opStack.Peek() is StopwordTerm))
                {
                    result = ExtractOperandFromStack(opStack);
                    if (result != null)
                    {
                        Array.Sort(result, new CompareByTfIdf());
                    }
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine("QueryProcessor -- exception [" + exc.Message + "] occured.");
                //  Exception is raised if the expression was constructed with
                //  the syntactic errors.
                //  Clear the stack and put special marker on the top of it
                Error  = ErrorStatus.IllegalQuerySyntax;
                result = null;
            }
            opStack.Clear();
            return(result);
        }
예제 #5
0
파일: QueryProcessor.cs 프로젝트: mo5h/omeo
 private static void IteratePostfixExpression(IList <QueryParserNode> postfixForm, TermIndexAccessor termIndex, Stack opStack)
 {
     for (int i = 0; i < postfixForm.Count; i++)
     {
         QueryParserNode node = postfixForm[i];
         if (node.NodeType == QueryParserNode.Type.eoTerm)
         {
             PushTermOnStack(((TermNode)node).Term, termIndex, opStack);
         }
         else
         if (node.NodeType == QueryParserNode.Type.eoSection)
         {
             UnarySectionOp(((SectionNode)node).SectionName, opStack);
         }
         else
         {
             BinaryOp(node, opStack);
         }
     }
 }
예제 #6
0
파일: QueryProcessor.cs 프로젝트: mo5h/omeo
 public static Entry[]  ProcessQuery(QueryPostfixForm postfixForm, TermIndexAccessor termIndex)
 {
     return(ProcessQuery(postfixForm, termIndex, false));
 }