コード例 #1
0
        private void CollectCoordinatedNounPhraseMentions(IParse nounPhrase, List <Mention> entities)
        {
            //System.err.println("collectCoordNp: "+np);
            List <IParse> nounPhraseTokens         = nounPhrase.Tokens;
            bool          inCoordinatedNounPhrase  = false;
            int           lastNounPhraseTokenIndex = mHeadFinder.GetHeadIndex(nounPhrase);

            for (int tokenIndex = lastNounPhraseTokenIndex - 1; tokenIndex >= 0; tokenIndex--)
            {
                IParse token     = nounPhraseTokens[tokenIndex];
                string tokenText = token.ToString();
                if (tokenText == "and" || tokenText == "or")
                {
                    if (lastNounPhraseTokenIndex != tokenIndex)
                    {
                        if (tokenIndex - 1 >= 0 && (nounPhraseTokens[tokenIndex - 1]).SyntacticType.StartsWith("NN"))
                        {
                            Util.Span nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex + 1]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                            Mention   nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                            entities.Add(nounPhraseSpanExtent);
                            //System.err.println("adding extent for conjunction in: "+np+" preeceeded by "+((Parse) npTokens.get(ti-1)).getSyntacticType());
                            inCoordinatedNounPhrase = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastNounPhraseTokenIndex = tokenIndex - 1;
                }
                else if (inCoordinatedNounPhrase && tokenText.Equals(","))
                {
                    if (lastNounPhraseTokenIndex != tokenIndex)
                    {
                        Util.Span nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex + 1]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                        Mention   nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                        entities.Add(nounPhraseSpanExtent);
                        //System.err.println("adding extent for comma in: "+np);
                    }
                    lastNounPhraseTokenIndex = tokenIndex - 1;
                }
                else if (inCoordinatedNounPhrase && tokenIndex == 0 && lastNounPhraseTokenIndex >= 0)
                {
                    Util.Span nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                    Mention   nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                    entities.Add(nounPhraseSpanExtent);
                    //System.err.println("adding extent for start coord in: "+np);
                }
            }
        }
コード例 #2
0
        private void CollectCoordinatedNounPhraseMentions(IParse nounPhrase, List <Mention> entities)
        {
            List <IParse> nounPhraseTokens         = nounPhrase.Tokens;
            bool          inCoordinatedNounPhrase  = false;
            int           lastNounPhraseTokenIndex = mHeadFinder.GetHeadIndex(nounPhrase);

            for (int tokenIndex = lastNounPhraseTokenIndex - 1; tokenIndex >= 0; tokenIndex--)
            {
                IParse token     = nounPhraseTokens[tokenIndex];
                string tokenText = token.ToString();
                if (tokenText == "and" || tokenText == "or")
                {
                    if (lastNounPhraseTokenIndex != tokenIndex)
                    {
                        if (tokenIndex - 1 >= 0 && PartsOfSpeech.IsNoun(nounPhraseTokens[tokenIndex - 1].SyntacticType))
                        {
                            var nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex + 1]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                            var nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                            entities.Add(nounPhraseSpanExtent);
                            inCoordinatedNounPhrase = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastNounPhraseTokenIndex = tokenIndex - 1;
                }
                else if (inCoordinatedNounPhrase && tokenText == PartsOfSpeech.Comma)
                {
                    if (lastNounPhraseTokenIndex != tokenIndex)
                    {
                        var nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex + 1]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                        var nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                        entities.Add(nounPhraseSpanExtent);
                    }
                    lastNounPhraseTokenIndex = tokenIndex - 1;
                }
                else if (inCoordinatedNounPhrase && tokenIndex == 0 && lastNounPhraseTokenIndex >= 0)
                {
                    var nounPhraseSpan       = new Util.Span((nounPhraseTokens[tokenIndex]).Span.Start, (nounPhraseTokens[lastNounPhraseTokenIndex]).Span.End);
                    var nounPhraseSpanExtent = new Mention(nounPhraseSpan, nounPhraseSpan, token.EntityId, null, "CNP");
                    entities.Add(nounPhraseSpanExtent);
                }
            }
        }
コード例 #3
0
        public MentionContext(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType, string nameType, int mentionIndex, int mentionsInSentence, int mentionIndexInDocument, int sentenceIndex, IHeadFinder headFinder) : base(span, headSpan, entityId, parse, extentType, nameType, headFinder)
        {
            mNounLocation    = mentionIndex;
            mMaxNounLocation = mentionsInSentence;
            mNounNumber      = mentionIndexInDocument;
            mSentenceNumber  = sentenceIndex;
            mIndexSpan       = parse.Span;
            mPreviousToken   = parse.PreviousToken;
            mNextToken       = parse.NextToken;
            mHead            = headFinder.GetLastHead(parse);
            List <IParse> headTokens = mHead.Tokens;

            Tokens          = headTokens.ToArray();
            mBasalNextToken = mHead.NextToken;
            //System.err.println("MentionContext.init: "+ent+" "+ent.getEntityId()+" head="+head);
            //mNonDescriptorStart = 0;
            InitializeHeads(headFinder.GetHeadIndex(mHead));
            mGender            = Similarity.GenderEnum.Unknown;
            mGenderProbability = 0d;
            mNumber            = Similarity.NumberEnum.Unknown;
            mNumberProbability = 0d;
        }
コード例 #4
0
        public MentionContext(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType, string nameType,
                              int mentionIndex, int mentionsInSentence, int mentionIndexInDocument, int sentenceIndex, IHeadFinder headFinder) :
            base(span, headSpan, entityId, parse, extentType, nameType, headFinder)
        {
            NounPhraseSentenceIndex    = mentionIndex;
            MaxNounPhraseSentenceIndex = mentionsInSentence;
            NounPhraseDocumentIndex    = mentionIndexInDocument;
            SentenceNumber             = sentenceIndex;
            IndexSpan     = parse.Span;
            PreviousToken = parse.PreviousToken;
            NextToken     = parse.NextToken;
            Head          = headFinder.GetLastHead(parse);
            List <IParse> headTokens = Head.Tokens;

            Tokens         = headTokens.ToArray();
            NextTokenBasal = Head.NextToken;
            //mNonDescriptorStart = 0;
            InitializeHeads(headFinder.GetHeadIndex(Head));
            mGender           = Similarity.GenderEnum.Unknown;
            GenderProbability = 0d;
            _number           = Similarity.NumberEnum.Unknown;
            NumberProbability = 0d;
        }
コード例 #5
0
 public MentionContext(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType, string nameType, int mentionIndex, int mentionsInSentence, int mentionIndexInDocument, int sentenceIndex, IHeadFinder headFinder)
     : base(span, headSpan, entityId, parse, extentType, nameType, headFinder)
 {
     mNounLocation = mentionIndex;
     mMaxNounLocation = mentionsInSentence;
     mNounNumber = mentionIndexInDocument;
     mSentenceNumber = sentenceIndex;
     mIndexSpan = parse.Span;
     mPreviousToken = parse.PreviousToken;
     mNextToken = parse.NextToken;
     mHead = headFinder.GetLastHead(parse);
     List<IParse> headTokens = mHead.Tokens;
     Tokens = headTokens.ToArray();
     mBasalNextToken = mHead.NextToken;
     //System.err.println("MentionContext.init: "+ent+" "+ent.getEntityId()+" head="+head);
     //mNonDescriptorStart = 0;
     InitializeHeads(headFinder.GetHeadIndex(mHead));
     mGender = Similarity.GenderEnum.Unknown;
     mGenderProbability = 0d;
     mNumber = Similarity.NumberEnum.Unknown;
     mNumberProbability = 0d;
 }
コード例 #6
0
ファイル: MentionContext.cs プロジェクト: gblosser/OpenNlp
        public MentionContext(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType, string nameType, 
            int mentionIndex, int mentionsInSentence, int mentionIndexInDocument, int sentenceIndex, IHeadFinder headFinder): 
            base(span, headSpan, entityId, parse, extentType, nameType, headFinder)
		{
            NounPhraseSentenceIndex = mentionIndex;
            MaxNounPhraseSentenceIndex = mentionsInSentence;
            NounPhraseDocumentIndex = mentionIndexInDocument;
			SentenceNumber = sentenceIndex;
			IndexSpan = parse.Span;
			PreviousToken = parse.PreviousToken;
			NextToken = parse.NextToken;
			Head = headFinder.GetLastHead(parse);
			List<IParse> headTokens = Head.Tokens;
            Tokens = headTokens.ToArray();
			NextTokenBasal = Head.NextToken;
			//mNonDescriptorStart = 0;
			InitializeHeads(headFinder.GetHeadIndex(Head));
            mGender = Similarity.GenderEnum.Unknown;
			GenderProbability = 0d;
            _number = Similarity.NumberEnum.Unknown;
			NumberProbability = 0d;
		}