GetFieldTermMap() 공개 메소드

public GetFieldTermMap ( String fieldName, String term ) : QueryPhraseMap
fieldName String
term String
리턴 QueryPhraseMap
예제 #1
0
        public void TestGetFieldTermMap()
        {
            Query      query = Tq("a");
            FieldQuery fq    = new FieldQuery(query, true, true);

            QueryPhraseMap pqm = fq.GetFieldTermMap(F, "a");

            Assert.NotNull(pqm);
            Assert.IsTrue(pqm.IsTerminal);

            pqm = fq.GetFieldTermMap(F, "b");
            Assert.Null(pqm);

            pqm = fq.GetFieldTermMap(F1, "a");
            Assert.Null(pqm);
        }
예제 #2
0
        /// <summary>
        /// a constructor. 
        /// </summary>
        /// <param name="fieldTermStack">FieldTermStack object</param>
        /// <param name="fieldQuery">FieldQuery object</param>
        /// <param name="phraseLimit">maximum size of phraseList</param>
        public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery, int phraseLimit)
        {
            String field = fieldTermStack.FieldName;

            LinkedList<TermInfo> phraseCandidate = new LinkedList<TermInfo>();
            QueryPhraseMap currMap = null;
            QueryPhraseMap nextMap = null;
            while (!fieldTermStack.IsEmpty() && (phraseList.Count < phraseLimit) )
            {

                phraseCandidate.Clear();

                TermInfo ti = fieldTermStack.Pop();
                currMap = fieldQuery.GetFieldTermMap(field, ti.Text);

                // if not found, discard top TermInfo from stack, then try next element
                if (currMap == null) continue;

                // if found, search the longest phrase
                phraseCandidate.AddLast(ti);
                while (true)
                {
                    ti = fieldTermStack.Pop();
                    nextMap = null;
                    if (ti != null)
                        nextMap = currMap.GetTermMap(ti.Text);
                    if (ti == null || nextMap == null)
                    {
                        if (ti != null)
                            fieldTermStack.Push(ti);
                        if (currMap.IsValidTermOrPhrase(new List<TermInfo>(phraseCandidate)))
                        {
                            AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
                        }
                        else
                        {
                            while (phraseCandidate.Count > 1)
                            {
                                TermInfo last = phraseCandidate.Last.Value;
                                phraseCandidate.RemoveLast();
                                fieldTermStack.Push(last);
                                currMap = fieldQuery.SearchPhrase(field, new List<TermInfo>(phraseCandidate));
                                if (currMap != null)
                                {
                                    AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
                                    break;
                                }
                            }
                        }
                        break;
                    }
                    else
                    {
                        phraseCandidate.AddLast(ti);
                        currMap = nextMap;
                    }
                }
            }
        }
예제 #3
0
        public void TestGetFieldTermMap()
        {
            Query query = Tq("a");
            FieldQuery fq = new FieldQuery(query, true, true);

            QueryPhraseMap pqm = fq.GetFieldTermMap(F, "a");
            Assert.NotNull(pqm);
            Assert.IsTrue(pqm.IsTerminal());

            pqm = fq.GetFieldTermMap(F, "b");
            Assert.Null(pqm);

            pqm = fq.GetFieldTermMap(F1, "a");
            Assert.Null(pqm);
        }
예제 #4
0
        /// <summary>
        /// a constructor.
        /// </summary>
        /// <param name="fieldTermStack">FieldTermStack object</param>
        /// <param name="fieldQuery">FieldQuery object</param>
        public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery)
        {
            String field = fieldTermStack.GetFieldName();

            LinkedList <TermInfo> phraseCandidate = new LinkedList <TermInfo>();
            QueryPhraseMap        currMap         = null;
            QueryPhraseMap        nextMap         = null;

            while (!fieldTermStack.IsEmpty())
            {
                phraseCandidate.Clear();

                TermInfo ti = fieldTermStack.Pop();
                currMap = fieldQuery.GetFieldTermMap(field, ti.GetText());

                // if not found, discard top TermInfo from stack, then try next element
                if (currMap == null)
                {
                    continue;
                }

                // if found, search the longest phrase
                phraseCandidate.AddLast(ti);
                while (true)
                {
                    ti      = fieldTermStack.Pop();
                    nextMap = null;
                    if (ti != null)
                    {
                        nextMap = currMap.GetTermMap(ti.GetText());
                    }
                    if (ti == null || nextMap == null)
                    {
                        if (ti != null)
                        {
                            fieldTermStack.Push(ti);
                        }
                        if (currMap.IsValidTermOrPhrase(new List <TermInfo>(phraseCandidate)))
                        {
                            AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.GetBoost(), currMap.GetTermOrPhraseNumber()));
                        }
                        else
                        {
                            while (phraseCandidate.Count > 1)
                            {
                                TermInfo last = phraseCandidate.Last.Value;
                                phraseCandidate.RemoveLast();
                                fieldTermStack.Push(last);
                                currMap = fieldQuery.SearchPhrase(field, new List <TermInfo>(phraseCandidate));
                                if (currMap != null)
                                {
                                    AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.GetBoost(), currMap.GetTermOrPhraseNumber()));
                                    break;
                                }
                            }
                        }
                        break;
                    }
                    else
                    {
                        phraseCandidate.AddLast(ti);
                        currMap = nextMap;
                    }
                }
            }
        }