Пример #1
0
        public static bool ExecuteTool(IEnumerable <IMaster> tools, string alias, IParse parser, Action <Exception> setError)
        {
            var tool = tools.FirstOrDefault(x => alias.StartsWith(x.Alias));

            if (tool == null)
            {
                return(false);
            }

            try {
                var a    = alias.Replace(tool.Alias, "").Trim();
                var args = tool.Parser?.Parse(a) ?? parser.Parse(a);
                if (args.Any() && args[0].Split(' ')[0].StartsWith("dev"))
                {
                    HandleDev(alias, tool.Parser ?? parser);
                    Console.WriteLine("Dev. Command handled!");
                    return(true);
                }
                tool.Execute(args, Launcher.Current.ShowData);
                return(true);
            } catch (Exception e) {
                setError(e);
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Tenta ler o vector a partir de um leitor de símbolos.
 /// </summary>
 /// <param name="reader">O leitor de símbolos.</param>
 /// <param name="parser">O interpretador do vector.</param>
 /// <param name="vector">Estabelece vector lido.</param>
 /// <returns>Verdadeiro caso a operação seja bem sucedida e falso caso contrário.</returns>
 public bool TryParseVector(
     MementoSymbolReader <InputReader, SymbValue, SymbType> reader,
     IParse <T, SymbValue, SymbType> parser,
     out IMathVector <T> vector)
 {
     return(this.TryParseVector(reader, parser, null, out vector));
 }
Пример #3
0
 // Since parsers are applied in pages in order, first parser
 // should have a lower page number than second parser. Otherwise
 // second parser won't be ever evaluated.
 public OrElse(IParse parser1, IParse parser2)
 {
     Parser1    = parser1;
     Parser2    = parser2;
     PageNumber = parser1.PageNumber;
     HasMatched = false;
 }
Пример #4
0
        public SetParser(IParse <ObjectType, string, ESymbolSetType> elementsParser)
        {
            if (elementsParser == null)
            {
                throw new ArgumentNullException("elementsParser");
            }
            else
            {
                this.expressionReader = new ExpressionReader <HashSet <ObjectType>, string, ESymbolSetType>(
                    new HashSetParser(elementsParser));
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.OPAR, ESymbolSetType.CPAR);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.LBRACK, ESymbolSetType.RBRACK);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.LANGLE, ESymbolSetType.RANGLE);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.LBRACK, ESymbolSetType.RANGLE);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.LANGLE, ESymbolSetType.RBRACK);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.VBAR, ESymbolSetType.VBAR);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.VBAR, ESymbolSetType.RANGLE);
                this.expressionReader.RegisterExternalDelimiterTypes(ESymbolSetType.LANGLE, ESymbolSetType.VBAR);

                this.expressionReader.RegisterBinaryOperator(ESymbolSetType.COMMA, this.Concatenate, 0);

                this.expressionReader.AddVoid(ESymbolSetType.SPACE);
                this.expressionReader.AddVoid(ESymbolSetType.CHANGE_LINE);
            }
        }
Пример #5
0
        /// <summary>
        /// Permite fazer a leitura de um vector.
        /// </summary>
        /// <typeparam name="T">O tipo de elementos do vector.</typeparam>
        /// <param name="dimension">A dimensão do vector a ser lido.</param>
        /// <param name="vectorText">O texto que representa o vector.</param>
        /// <param name="vectorFactory">A fábrica responsável pela criação de vectores.</param>
        /// <param name="elementParser">O leitor de elementos.</param>
        /// <param name="readNegativeNumbers">Indica se são lidos os números negativos.</param>
        /// <returns></returns>
        public static IMathVector <T> ReadVector <T>(
            int dimension,
            string vectorText,
            IMathVectorFactory <T> vectorFactory,
            IParse <T, string, string> elementParser,
            bool readNegativeNumbers = false)
        {
            var reader             = new StringReader(vectorText);
            var stringSymbolReader = new StringSymbolReader(reader, readNegativeNumbers);
            var arrayVectorReader  = new ConfigVectorReader <T, string, string, CharSymbolReader <string> >(
                dimension,
                vectorFactory);

            arrayVectorReader.MapInternalDelimiters("left_bracket", "right_bracket");
            arrayVectorReader.AddBlanckSymbolType("blancks");
            arrayVectorReader.SeparatorSymbType = "comma";

            var vector = default(IMathVector <T>);

            if (arrayVectorReader.TryParseVector(stringSymbolReader, elementParser, out vector))
            {
                return(vector);
            }
            else
            {
                throw new Exception("Can't read vector.");
            }
        }
Пример #6
0
        /// <summary>
        /// Permite fazer a leitura de um polinómio genérico a partir de uma reprsentação textual.
        /// </summary>
        /// <typeparam name="T">O tipo de dados associado aos coeficientes.</typeparam>
        /// <param name="polynomialRepresentation">A representação textual do polinómio.</param>
        /// <param name="polynomialRing">O anel responsável pelas operações sobre os coeficientes.</param>
        /// <param name="coeffsParser">O leitor de coeficientes.</param>
        /// <param name="conversion">O conversor entre inteiros e o tiop de coeficiente.</param>
        /// <param name="readNegativeNumbers">
        /// Indica se os números negativos são para ser lidos ou se é lido
        /// o sinal e depois o respectivo valor como símbolos independentes.</param>
        /// <returns></returns>
        public static Polynomial <T> ReadPolynomial <T>(
            string polynomialRepresentation,
            IRing <T> polynomialRing,
            IConversion <int, T> conversion,
            IParse <T, string, string> coeffsParser,
            bool readNegativeNumbers = false)
        {
            var polInputReader  = new StringReader(polynomialRepresentation);
            var polSymbolReader = new StringSymbolReader(polInputReader, readNegativeNumbers);
            var polParser       = new PolynomialReader <T, CharSymbolReader <string> >(
                coeffsParser,
                polynomialRing);

            var result = default(Polynomial <T>);

            if (polParser.TryParsePolynomial(polSymbolReader, conversion, out result))
            {
                // O polinómio foi lido com sucesso.
                return(result);
            }
            else
            {
                // Não é possível ler o polinómio.
                throw new Exception("Can't read polynomial.");
            }
        }
Пример #7
0
        /// <summary>
        /// Permit realizar a leitura de um polinómio com coeficientes fraccionários.
        /// </summary>
        /// <typeparam name="T">O tipo de dados dos componentes das fracções.</typeparam>
        /// <param name="polynomialRepresentation">A representação polinomial.</param>
        /// <param name="domain">O domínio responsável pelas operações sobre os elementos das fracções.</param>
        /// <param name="itemsParser">O leitor de elementos da fracção.</param>
        /// <param name="conversion">A conversão entre cada fracção e o valor inteiro.</param>
        /// <param name="variableName">O nome da variável.</param>
        /// <param name="readNegativeNumbers">Indica se são lidos os números negativos.</param>
        /// <returns>O polinómio lido.</returns>
        public static UnivariatePolynomialNormalForm <Fraction <T> > ReadFractionalCoeffsUnivarPol <T, D>(
            string polynomialRepresentation,
            D domain,
            IParse <T, string, string> itemsParser,
            IConversion <int, Fraction <T> > conversion,
            string variableName,
            bool readNegativeNumbers = false) where D : IEuclidenDomain <T>
        {
            var fractionField  = new FractionField <T>(domain);
            var fractionParser = new FieldDrivenExpressionParser <Fraction <T> >(
                new SimpleElementFractionParser <T>(itemsParser, domain),
                fractionField);
            var polInputReader  = new StringReader(polynomialRepresentation);
            var polSymbolReader = new StringSymbolReader(polInputReader, readNegativeNumbers);
            var polParser       = new UnivariatePolynomialReader <Fraction <T>, CharSymbolReader <string> >(
                "x",
                fractionParser,
                fractionField);

            var result = default(UnivariatePolynomialNormalForm <Fraction <T> >);

            if (polParser.TryParsePolynomial(polSymbolReader, conversion, out result))
            {
                // O polinómio foi lido com sucesso.
                return(result);
            }
            else
            {
                // Não é possível ler o polinómio.
                throw new Exception("Can't read polynomial.");
            }
        }
Пример #8
0
        /// <summary>
        /// Permite fazer a leitura de uma matriz.
        /// </summary>
        /// <typeparam name="T">O tipo de elementos na matriz.</typeparam>
        /// <param name="lines">O número de linhas.</param>
        /// <param name="columns">O número de colunas.</param>
        /// <param name="matrixText">A representação textual da matriz.</param>
        /// <param name="matrixFactory">A fábrica responsável pela criação de matrizes.</param>
        /// <param name="elementParser">O leitor de elementos.</param>
        /// <param name="readNegativeNumbers">Indica se são lidos os números negativos.</param>
        /// <returns>A matriz.</returns>
        public static M ReadMatrix <T, M>(
            int lines,
            int columns,
            string matrixText,
            Func <int, int, M> matrixFactory,
            IParse <T, string, string> elementParser,
            bool readNegativeNumbers = false)
            where M : IMatrix <T>
        {
            var reader             = new StringReader(matrixText);
            var stringSymbolReader = new StringSymbolReader(reader, readNegativeNumbers);
            var arrayMatrixReader  = new ConfigMatrixReader <T, M, string, string>(
                lines,
                columns);

            arrayMatrixReader.MapInternalDelimiters("left_bracket", "right_bracket");
            arrayMatrixReader.AddBlanckSymbolType("blancks");
            arrayMatrixReader.SeparatorSymbType = "comma";

            var matrix = default(M);

            if (arrayMatrixReader.TryParseMatrix(
                    stringSymbolReader,
                    elementParser,
                    matrixFactory,
                    out matrix))
            {
                return(matrix);
            }
            else
            {
                throw new Exception("Can't read matrix.");
            }
        }
Пример #9
0
        private static string GetEntityType(IParse headToken)
        {
            string entityType;

            for (IParse parent = headToken.Parent; parent != null; parent = parent.Parent)
            {
                entityType = parent.EntityType;
                if (entityType != null)
                {
                    return(entityType);
                }
                if (parent.IsSentence)
                {
                    break;
                }
            }
            List <IParse> tokenChildren   = headToken.Children;
            int           tokenChildCount = tokenChildren.Count;

            if (tokenChildCount > 0)
            {
                IParse tokenChild = tokenChildren[tokenChildCount - 1];
                entityType = tokenChild.EntityType;
                if (entityType != null)
                {
                    return(entityType);
                }
            }
            return(null);
        }
Пример #10
0
        /// <summary>
        /// Permite realizar a leitura de um polinómio a partir de uma representação textual.
        /// </summary>
        /// <typeparam name="T">O tipo dos coeficientes do polinómio.</typeparam>
        /// <param name="polynomialRepresentation">A representação textual do polinómio.</param>
        /// <param name="ring">O anel responsável pelas operações sobre os coeficientes.</param>
        /// <param name="coeffsParser">O leitor de representações textuais para os coeficientes.</param>
        /// <param name="conversion">A conversão do tipo do coeficientes para inteiro.</param>
        /// <param name="externalDelimitersTypes">Os delimitadores externos.</param>
        /// <param name="readNegativeNumbers">Indica se o leitor identifica números negativos.</param>
        /// <returns>O polinómio lido a partir da representação textual.</returns>
        public static Polynomial <T> ReadPolynomial <T>(
            string polynomialRepresentation,
            IRing <T> ring,
            IParse <T, string, string> coeffsParser,
            IConversion <int, T> conversion,
            Dictionary <string, string> externalDelimitersTypes,
            bool readNegativeNumbers = false)
        {
            var polInputReader  = new StringReader(polynomialRepresentation);
            var polSymbolReader = new StringSymbolReader(polInputReader, readNegativeNumbers);
            var polParser       = new PolynomialReader <T, CharSymbolReader <string> >(
                coeffsParser,
                ring);

            foreach (var kvp in externalDelimitersTypes)
            {
                polParser.RegisterExternalDelimiterTypes(kvp.Key, kvp.Value);
            }

            var result = default(Polynomial <T>);

            if (polParser.TryParsePolynomial(polSymbolReader, conversion, out result))
            {
                // O polinómio foi lido com sucesso.
                return(result);
            }
            else
            {
                // Não é possível ler o polinómio.
                throw new Exception("Can't read polynomial.");
            }
        }
Пример #11
0
        private void CollectPossessivePronouns(IParse nounPhrase, List <Mention> entities)
        {
            //TODO: Look at how training is done and examine whether this is needed or can be accomidated in a different way.

            /*
             * List snps = np.getSubNounPhrases();
             * if (snps.size() != 0) {
             * for (int si = 0, sl = snps.size(); si < sl; si++) {
             * Parse snp = (Parse) snps.get(si);
             * Extent ppExtent = new Extent(snp.getSpan(), snp.getSpan(), snp.getEntityId(), null,Linker.PRONOUN_MODIFIER);
             * entities.add(ppExtent);
             * }
             * }
             * else {
             */
            List <IParse> nounPhraseTokens = nounPhrase.Tokens;
            IParse        headToken        = mHeadFinder.GetHeadToken(nounPhrase);

            for (int tokenIndex = nounPhraseTokens.Count - 2; tokenIndex >= 0; tokenIndex--)
            {
                IParse token = nounPhraseTokens[tokenIndex];
                if (token == headToken)
                {
                    continue;
                }
                if (PartsOfSpeech.IsPersonalOrPossessivePronoun(token.SyntacticType) && IsHandledPronoun(token.ToString()))
                {
                    var possessivePronounExtent = new Mention(token.Span, token.Span, token.EntityId, null, Linker.PronounModifier);
                    entities.Add(possessivePronounExtent);
                    break;
                }
            }
            //}
        }
Пример #12
0
        protected internal virtual bool IsPossessive(IParse nounPhrase)
        {
            List <IParse> parts = nounPhrase.SyntacticChildren;

            if (parts.Count > 1)
            {
                if (parts[0].IsNounPhrase)
                {
                    List <IParse> childTokens = parts[0].Tokens;
                    IParse        token       = childTokens[childTokens.Count - 1];
                    if (token.SyntacticType == PartsOfSpeech.PossessiveEnding)
                    {
                        return(true);
                    }
                }
            }
            if (parts.Count > 2)
            {
                if (parts[1].IsToken && parts[1].SyntacticType == PartsOfSpeech.PossessiveEnding &&
                    parts[0].IsNounPhrase && parts[2].IsNounPhrase)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #13
0
        public void UkrainianDeclension()
        {
            var webClient = new Mock <IWebClient>();

            webClient.Setup(client => client.QueryString).Returns(new NameValueCollection());
            webClient.Setup(client => client.DownloadString(It.IsAny <string>())).Returns(DeclensionResultText);
            var morpherClient = new MorpherClient(null, null, webClient.Object);

            var declension = new Declension(morpherClient.Ukrainian);

            IParse parsedResult = declension.Parse("помідор");

            Assert.IsNotNull(parsedResult);
            Assert.AreEqual("помідор", parsedResult.Nominative);
            Assert.AreEqual("помідора", parsedResult.Genitive);
            Assert.AreEqual("помідору", parsedResult.Dative);
            Assert.AreEqual("помідора", parsedResult.Accusative);
            Assert.AreEqual("помідором", parsedResult.Instrumental);
            Assert.AreEqual("помідорі", parsedResult.Prepositional);
            Assert.AreEqual("помідоре", parsedResult.Vocative);
            Assert.IsNull(parsedResult.Gender);

            webClient.Verify(client => client.QueryString, Times.AtLeastOnce());
            webClient.Verify(client => client.DownloadString(It.IsAny <string>()), Times.Once());
        }
Пример #14
0
 /// <summary>
 /// Instancia um novo objecto do tipo <see cref="UnivarPolNormalFormParser{CoeffType} "/>.
 /// </summary>
 /// <param name="variable">O nome da variável associada ao polinómio.</param>
 /// <param name="conversion">O objecto responsável pela conversão entre coeficientes e inteiros.</param>
 /// <param name="elementsParser">O leitor de coeficientes.</param>
 /// <param name="ring">O anel responsável pelas operações sobre os coeficientes.</param>
 public UnivarPolNormalFormParser(
     string variable,
     IConversion <int, CoeffType> conversion,
     IParse <CoeffType, string, string> elementsParser,
     IRing <CoeffType> ring)
 {
     if (string.IsNullOrWhiteSpace(variable))
     {
         throw new ArgumentException("Variable must hava a non empty value.");
     }
     else if (conversion == null)
     {
         throw new ArgumentNullException("conversion");
     }
     else if (ring == null)
     {
         throw new ArgumentNullException("ring");
     }
     else if (elementsParser == null)
     {
         throw new ArgumentNullException("elementsParser");
     }
     else
     {
         this.conversion       = conversion;
         this.polynomialReader = new UnivariatePolynomialReader <CoeffType, ISymbol <string, string>[]>(
             variable,
             elementsParser,
             ring);
     }
 }
Пример #15
0
        private Mention[] CollectMentions(List <IParse> nounPhrases, Dictionary <IParse, IParse> headMap)
        {
            List <Mention> mentions = new List <Mention>(nounPhrases.Count);

            Util.Set <IParse> recentMentions = new Util.HashSet <IParse>();
            //System.err.println("AbtractMentionFinder.collectMentions: "+headMap);
            for (int nounPhraseIndex = 0; nounPhraseIndex < nounPhrases.Count; nounPhraseIndex++)
            {
                IParse nounPhrase = nounPhrases[nounPhraseIndex];
                //System.err.println("AbstractMentionFinder: collectMentions: np[" + npi + "]=" + np + " head=" + headMap.get(np));
                if (!IsHeadOfExistingMention(nounPhrase, headMap, recentMentions))
                {
                    ClearMentions(recentMentions, nounPhrase);
                    if (!IsPartOfName(nounPhrase))
                    {
                        IParse  head   = mHeadFinder.GetLastHead(nounPhrase);
                        Mention extent = new Mention(nounPhrase.Span, head.Span, head.EntityId, nounPhrase, null);
                        //System.err.println("adding "+np+" with head "+head);
                        mentions.Add(extent);
                        recentMentions.Add(nounPhrase);
                        // determine name-entity type
                        string entityType = GetEntityType(mHeadFinder.GetHeadToken(head));
                        if (entityType != null)
                        {
                            extent.NameType = entityType;
                        }
                    }
                    else
                    {
                        //System.err.println("AbstractMentionFinder.collectMentions excluding np as part of name. np=" + np);
                    }
                }
                else
                {
                    //System.err.println("AbstractMentionFinder.collectMentions excluding np as head of previous mention. np=" + np);
                }
                if (IsBasalNounPhrase(nounPhrase))
                {
                    if (mPrenominalNamedEntitiesCollection)
                    {
                        CollectPrenominalNamedEntities(nounPhrase, mentions);
                    }
                    if (mCoordinatedNounPhrasesCollection)
                    {
                        CollectCoordinatedNounPhraseMentions(nounPhrase, mentions);
                    }
                    CollectPossessivePronouns(nounPhrase, mentions);
                }
                else
                {
                    // Could use to get NP -> tokens CON structures for basal nps including NP -> NAC tokens
                    //collectComplexNounPhrases(np,mentions);
                }
            }

            mentions.Sort();
            RemoveDuplicates(mentions);
            return(mentions.ToArray());
        }
Пример #16
0
 public Mention(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType)
 {
     mSpan = span;
     mHeadSpan = headSpan;
     mId = entityId;
     mType = extentType;
     mParse = parse;
 }
Пример #17
0
        public LoggerParser(IParse parser)
        {
            _parser = parser;
            string rootPath = Directory.GetCurrentDirectory() + "\\Logs.txt";

            InvokeFuncWithLogException(u => !File.Exists(u) ? File.CreateText(u) : null, rootPath);
            _pathToLog = rootPath;
        }
Пример #18
0
 public Validate(Predicate <IDictionary <String, String> > predicate, IParse p)
 {
     this.Predicate  = predicate;
     this.P          = p;
     this.Key        = p.Key;
     this.PageNumber = p.PageNumber;
     this.Default    = p.Default;
 }
Пример #19
0
 /// <summary>
 /// Tenta ler a matriz a partir de um leitor de símbolos.
 /// </summary>
 /// <param name="reader">O leitor de símbolos.</param>
 /// <param name="parser">O interpretador da matriz.</param>
 /// <param name="matrix">Estabelece a matriz lida.</param>
 /// <param name="matrixFactory">A função responsável pela criação das matrizes.</param>
 /// <returns>Verdadeiro caso a operação seja bem sucedida e falso caso contrário.</returns>
 public bool TryParseMatrix(
     IMementoSymbolReader <SymbValue, SymbType> reader,
     IParse <T, SymbValue, SymbType> parser,
     Func <int, int, M> matrixFactory,
     out M matrix)
 {
     return(this.TryParseMatrix(reader, parser, null, matrixFactory, out matrix));
 }
Пример #20
0
 /// <summary>
 /// Instancia um novo objecto do tipo <see cref="FieldDrivenExpressionReader{ObjectType, InputType}"/>.
 /// </summary>
 /// <param name="objectParser">O leitor de objectos.</param>
 /// <param name="field">O corpo.</param>
 /// <param name="integerNumber">O número inteiro.</param>
 public FieldDrivenExpressionReader(
     IParse <ObjectType, string, string> objectParser,
     IField <ObjectType> field,
     IIntegerNumber <ObjectType> integerNumber = null) : base(objectParser, field, integerNumber)
 {
     // A verificação de nulidade do campo é levada a cabo na classe base.
     this.field = field;
 }
        public parser_window(Object cat, String title)
        {
            InitializeComponent();
            Windows.setWindowChrome(this);
            Windows.parserWindow = this;

            this.cat            = (IParse)cat;
            this.label.Content += " (" + title + ")";
        }
Пример #22
0
 public PlaceDetailPage(Place place)
 {
     _place             = place;
     _parse             = DependencyService.Get <IParse> ();
     _user              = _parse.GetCurrentUser();
     _reviewsCollection = new ObservableCollection <Review> ();
     InitializeComponents();
     LoadData().ConfigureAwait(false);
 }
Пример #23
0
 public Mention(Util.Span span, Util.Span headSpan, int entityId, IParse parse, string extentType, string nameType)
 {
     mSpan     = span;
     mHeadSpan = headSpan;
     mId       = entityId;
     mType     = extentType;
     mParse    = parse;
     mNameType = nameType;
 }
        /// <summary>
        /// Returns the bottom-most head of a <code>IParse</code>.  If no
        /// head is available which is a child of <code>parse</code> then
        /// <code>parse</code> is returned.
        /// </summary>
        public IParse GetLastHead(IParse parse)
        {
            IParse head;

            while (null != (head = GetHead(parse)))
            {
                parse = head;
            }
            return(parse);
        }
Пример #25
0
        public virtual Mention[] GetMentions(IParse parse)
        {
            List <IParse> nounPhrases = parse.NounPhrases;

            nounPhrases.Sort();
            Dictionary <IParse, IParse> headMap = ConstructHeadMap(nounPhrases);

            Mention[] mentions = CollectMentions(nounPhrases, headMap);
            return(mentions);
        }
Пример #26
0
 public IfThen(Func <String, bool> predicate, IParse @if, IParse then, IParse @else)
 {
     this.Predicate  = predicate;
     this.If         = @if;
     this.Then       = then;
     this.Else       = @else;
     _wasEvaluated   = false;
     _predicateHolds = false;
     _output         = new Dictionary <string, string>();
 }
Пример #27
0
        public virtual Mention[] GetMentions(IParse parse)
        {
            var nounPhrases = parse.NounPhrases;

            nounPhrases.Sort();
            var headMap  = ConstructHeadMap(nounPhrases);
            var mentions = CollectMentions(nounPhrases, headMap);

            return(mentions);
        }
Пример #28
0
        /*/// <summary>
         * /// Constructs context information for the specified mention.
         * /// </summary>
         * /// <param name="mentionParse">
         * /// Mention parse structure for which context is to be constructed.
         * /// </param>
         * /// <param name="mentionIndex">
         * /// mention position in sentence.
         * /// </param>
         * /// <param name="mentionsInSentence">
         * /// Number of mentions in the sentence.
         * /// </param>
         * /// <param name="mentionsInDocument">
         * /// Number of mentions in the document.
         * /// </param>
         * /// <param name="sentenceIndex">
         * /// Sentence number for this mention.
         * /// </param>
         * /// <param name="nameType">
         * /// The named-entity type for this mention.
         * /// </param>
         * /// <param name="headFinder">
         * /// Object which provides head information.
         * /// </param>
         * public MentionContext(Parse mentionParse, int mentionIndex, int mentionsInSentence, int mentionsInDocument, int sentenceIndex, string nameType, HeadFinder headFinder) {
         * nounLocation = mentionIndex;
         * maxNounLocation = mentionsInDocument;
         * sentenceNumber = sentenceIndex;
         * parse = mentionParse;
         * indexSpan = mentionParse.getSpan();
         * prevToken = mentionParse.getPreviousToken();
         * nextToken = mentionParse.getNextToken();
         * head = headFinder.getLastHead(mentionParse);
         * List headTokens = head.getTokens();
         * tokens = (Parse[]) headTokens.toArray(new Parse[headTokens.size()]);
         * basalNextToken = head.getNextToken();
         * indexHeadSpan = head.getSpan();
         * nonDescriptorStart = 0;
         * initHeads(headFinder.getHeadIndex(head));
         * this.neType= nameType;
         * if (PartsOfSpeech.IsNoun(getHeadTokenTag()) && !PartsOfSpeech.IsProperNoun(getHeadTokenTag())) {
         * //if (PartsOfSpeech.IsProperNoun(headTokenTag) && neType != null) {
         * this.synsets = getSynsetSet(this);
         * }
         * else {
         * this.synsets=Collections.EMPTY_SET;
         * }
         * gender = GenderEnum.UNKNOWN;
         * this.genderProb = 0d;
         * number = NumberEnum.UNKNOWN;
         * this.numberProb = 0d;
         * }
         */

        private void InitializeHeads(int headIndex)
        {
            HeadTokenIndex = headIndex;
            mHeadToken     = (IParse)Tokens[HeadTokenIndex];
            HeadTokenText  = mHeadToken.ToString();
            HeadTokenTag   = mHeadToken.SyntacticType;
            FirstToken     = (IParse)Tokens[0];
            FirstTokenTag  = FirstToken.SyntacticType;
            FirstTokenText = FirstToken.ToString();
        }
Пример #29
0
        public virtual Mention[] GetMentions(IParse parse)
        {
            List <IParse> nounPhrases = parse.NounPhrases;

            nounPhrases.Sort();
            Dictionary <IParse, IParse> headMap = ConstructHeadMap(nounPhrases);

            //System.err.println("AbstractMentionFinder.getMentions: got " + nps.size()); // + " nps, and " + nes.size() + " named entities");
            Mention[] mentions = CollectMentions(nounPhrases, headMap);
            return(mentions);
        }
Пример #30
0
        public AndThen(String key, Func <IDictionary <string, string>, string> factory, IParse first, IParse second)
            : base(key, factory)
        {
            First      = first;
            Second     = second;
            PageNumber = first.PageNumber;
            HasMatched = false;

            _firstHasMatched = false;
            _firstResult     = new Dictionary <string, string>();
        }
Пример #31
0
        private static void ClearMentions(Util.Set <IParse> mentions, IParse nounPhrase)
        {
            Util.Span nounPhraseSpan = nounPhrase.Span;

            //loop backwards through the set so that we can remove from the end forwards
            for (int currentMention = mentions.Count - 1; currentMention > -1; currentMention--)
            {
                if (mentions[currentMention].Span.Contains(nounPhraseSpan))
                {
                    mentions.Remove(mentions[currentMention]);
                }
            }
        }
Пример #32
0
		private void GatherHeads(IParse parse, Dictionary<IParse, IParse> heads)
		{
			IParse head = mHeadFinder.GetHead(parse);
			if (head != null)
			{
				heads[head] = parse;
			}

			List<IParse> nounPhrases = parse.NounPhrases;
            foreach (IParse currentNounPhrase in nounPhrases)
            {
                GatherHeads(currentNounPhrase, heads);
            }
		}
Пример #33
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;
     //System.err.println("MentionContext.init: "+ent+" "+ent.getEntityId()+" head="+head);
     //mNonDescriptorStart = 0;
     InitializeHeads(headFinder.GetHeadIndex(Head));
     mGender = Similarity.GenderEnum.Unknown;
     GenderProbability = 0d;
     _number = Similarity.NumberEnum.Unknown;
     NumberProbability = 0d;
 }
 private void CollectPossessivePronouns(IParse nounPhrase, List<Mention> entities)
 {
     //TODO: Look at how training is done and examine whether this is needed or can be accomidated in a different way.
     /*
     List snps = np.getSubNounPhrases();
     if (snps.size() != 0) {
     //System.err.println("AbstractMentionFinder: Found existing snps");
     for (int si = 0, sl = snps.size(); si < sl; si++) {
     Parse snp = (Parse) snps.get(si);
     Extent ppExtent = new Extent(snp.getSpan(), snp.getSpan(), snp.getEntityId(), null,Linker.PRONOUN_MODIFIER);
     entities.add(ppExtent);
     }
     }
     else {
     */
     //System.err.println("AbstractEntityFinder.collectPossesivePronouns: "+np);
     List<IParse> nounPhraseTokens = nounPhrase.Tokens;
     IParse headToken = mHeadFinder.GetHeadToken(nounPhrase);
     for (int tokenIndex = nounPhraseTokens.Count - 2; tokenIndex >= 0; tokenIndex--)
     {
         IParse token = nounPhraseTokens[tokenIndex];
         if (token == headToken)
         {
             continue;
         }
         if (token.SyntacticType.StartsWith("PRP") && IsHandledPronoun(token.ToString()))
         {
             Mention possessivePronounExtent = new Mention(token.Span, token.Span, token.EntityId, null, OpenNLP.Tools.Coreference.Linker.PronounModifier);
             //System.err.println("AbstractEntityFinder.collectPossesivePronouns: adding possesive pronoun: "+tok+" "+tok.getEntityId());
             entities.Add(possessivePronounExtent);
             //System.err.println("AbstractMentionFinder: adding pos-pro: "+ppExtent);
             break;
         }
     }
     //}
 }
 public IParse GetHeadToken(IParse parse)
 {
     List<IParse> tokens = parse.Tokens;
     return tokens[GetHeadIndex(parse)];
 }
Пример #36
0
		private static bool IsPartOfName(IParse nounPhrase)
		{
			string entityType;
			for (IParse parent = nounPhrase.Parent; parent != null; parent = parent.Parent)
			{
				entityType = parent.EntityType;
				if (entityType != null)
				{
					if (!nounPhrase.Span.Contains(parent.Span))
					{
						return true;
					}
				}
				if (parent.IsSentence)
				{
					break;
				}
			}
			return false;
		}
Пример #37
0
		public virtual Mention[] GetMentions(IParse parse)
		{
			List<IParse> nounPhrases = parse.NounPhrases;
			nounPhrases.Sort();
            Dictionary<IParse, IParse> headMap = ConstructHeadMap(nounPhrases);
			Mention[] mentions = CollectMentions(nounPhrases, headMap);
			return mentions;
		}
Пример #38
0
		/*/// <summary> 
        /// Adds a mention for the non-treebank-labeled possesive noun phrases.  
        /// </summary>
		/// <param name="possesiveNounPhrase">
        /// The possessive noun phase which may require an additional mention.
		/// </param>
		/// <param name="mentions">
        /// The list of mentions into which a new mention can be added. 
		/// </param>
        private void AddPossessiveMentions(IParse possessiveNounPhrase, List<Mention> mentions)
        {
            List<IParse> kids = possessiveNounPhrase.SyntacticChildren;
            if (kids.Count > 1)
            {
                IParse firstToken = kids[1];
                if (firstToken.IsToken && firstToken.SyntacticType != "POS")
                {
                    IParse lastToken = kids[kids.Count - 1];
                    if (lastToken.IsToken)
                    {
                        var extentSpan = new Util.Span(firstToken.Span.Start, lastToken.Span.End);
                        var extent = new Mention(extentSpan, extentSpan, - 1, null, null);
                        mentions.Add(extent);
                    }
                    else
                    {
                        Console.Error.WriteLine("AbstractMentionFinder.AddPossessiveMentions: odd parse structure: " + possessiveNounPhrase);
                    }
                }
            }
        }*/
		
		private void CollectPrenominalNamedEntities(IParse nounPhrase, List<Mention> extents)
		{
			IParse headToken = mHeadFinder.GetHeadToken(nounPhrase);
            List<IParse> namedEntities = nounPhrase.NamedEntities;
            Util.Span headTokenSpan = headToken.Span;
			for (int namedEntityIndex = 0; namedEntityIndex < namedEntities.Count; namedEntityIndex++)
			{
				IParse namedEntity = namedEntities[namedEntityIndex];
				if (!namedEntity.Span.Contains(headTokenSpan))
				{
					var extent = new Mention(namedEntity.Span, namedEntity.Span, namedEntity.EntityId, null, "NAME");
					extent.NameType = namedEntity.EntityType;
					extents.Add(extent);
				}
			}
		}
Пример #39
0
        private static bool IsHeadOfExistingMention(IParse nounPhrase, Dictionary<IParse, IParse> headMap, Util.Set<IParse> mentions)
		{
            IParse head = nounPhrase;
            while (headMap.ContainsKey(head))
            {
                head = headMap[head];
                if (mentions.Contains(head))
                {
                    return true;
                }
            }
            return false;
        }
Пример #40
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);
				}
			}
		}
Пример #41
0
		protected internal virtual bool IsOfPrepPhrase(IParse nounPhrase)
		{
			List<IParse> parts = nounPhrase.SyntacticChildren;
			if (parts.Count == 2)
			{
                if (parts[0].IsNounPhrase)
				{
                    List<IParse> childParts = parts[1].SyntacticChildren;
                    if (childParts.Count == 2)
					{
                        if (childParts[0].IsToken && childParts[0].ToString() == "of")
						{
							return true;
						}
					}
				}
			}
			return false;
		}
 public virtual Mention[] GetMentions(IParse parse)
 {
     List<IParse> nounPhrases = parse.NounPhrases;
     nounPhrases.Sort();
     Dictionary<IParse, IParse> headMap = ConstructHeadMap(nounPhrases);
     //System.err.println("AbstractMentionFinder.getMentions: got " + nps.size()); // + " nps, and " + nes.size() + " named entities");
     Mention[] mentions = CollectMentions(nounPhrases, headMap);
     return mentions;
 }
Пример #43
0
		protected internal virtual bool IsConjoinedBasal(IParse nounPhrase)
		{
			List<IParse> parts = nounPhrase.SyntacticChildren;
			bool allToken = true;
			bool hasConjunction = false;
            foreach (IParse currentPart in parts)
			{
                if (currentPart.IsToken)
				{
                    if (currentPart.SyntacticType == PartsOfSpeech.CoordinatingConjunction)
					{
						hasConjunction = true;
					}
				}
				else
				{
					allToken = false;
					break;
				}
			}
			return (allToken && hasConjunction);
		}
Пример #44
0
		public int GetHeadIndex(IParse parse)
		{
			List<IParse> syntacticChildren = parse.SyntacticChildren;
			bool countTokens = false;
			int tokenCount = 0;
			//check for NP -> NN S type structures and return last token before S as head.
            for (int currentSyntacticChild = 0; currentSyntacticChild < syntacticChildren.Count; currentSyntacticChild++)
			{
				IParse syntacticChild = syntacticChildren[currentSyntacticChild];
				if (syntacticChild.SyntacticType.StartsWith("S"))
				{
					if (currentSyntacticChild != 0)
					{
						countTokens = true;
					}
				}
				if (countTokens)
				{
					tokenCount += syntacticChild.Tokens.Count;
				}
			}
			List<IParse> tokens = parse.Tokens;
			if (tokens.Count == 0)
			{
				Console.Error.WriteLine("PTBHeadFinder.getHeadIndex(): empty tok list for parse " + parse);
			}
			for (int currentToken = tokens.Count - tokenCount - 1; currentToken >= 0; currentToken--)
			{
				IParse token = tokens[currentToken];
				if (!mSkipSet.Contains(token.SyntacticType))
				{
					return currentToken;
				}
			}
			return (tokens.Count - tokenCount - 1);
		}
Пример #45
0
		private void CollectPossessivePronouns(IParse nounPhrase, List<Mention> entities)
		{
			//TODO: Look at how training is done and examine whether this is needed or can be accomidated in a different way.
			/*
			List snps = np.getSubNounPhrases();
			if (snps.size() != 0) {
			for (int si = 0, sl = snps.size(); si < sl; si++) {
			Parse snp = (Parse) snps.get(si);
			Extent ppExtent = new Extent(snp.getSpan(), snp.getSpan(), snp.getEntityId(), null,Linker.PRONOUN_MODIFIER);
			entities.add(ppExtent);
			}
			}
			else {
			*/
			List<IParse> nounPhraseTokens = nounPhrase.Tokens;
			IParse headToken = mHeadFinder.GetHeadToken(nounPhrase);
			for (int tokenIndex = nounPhraseTokens.Count - 2; tokenIndex >= 0; tokenIndex--)
			{
				IParse token = nounPhraseTokens[tokenIndex];
				if (token == headToken)
				{
					continue;
				}
				if (PartsOfSpeech.IsPersOrPossPronoun(token.SyntacticType) && IsHandledPronoun(token.ToString()))
				{
					var possessivePronounExtent = new Mention(token.Span, token.Span, token.EntityId, null, Linker.PronounModifier);
					entities.Add(possessivePronounExtent);
					break;
				}
			}
			//}
		}
Пример #46
0
		/// <summary>
        /// Returns the bottom-most head of a <code>IParse</code>.  If no
		/// head is available which is a child of <code>parse</code> then
		/// <code>parse</code> is returned. 
		/// </summary>
		public IParse GetLastHead(IParse parse)
		{
			IParse head;

            while (null != (head = GetHead(parse)))
			{
                parse = head;
			}
            return parse;
		}
Пример #47
0
        private static void ClearMentions(Util.Set<IParse> mentions, IParse nounPhrase)
		{
			Util.Span nounPhraseSpan = nounPhrase.Span;

            //loop backwards through the set so that we can remove from the end forwards
            for (int currentMention = mentions.Count - 1; currentMention > -1; currentMention--)
            {
                if (mentions[currentMention].Span.Contains(nounPhraseSpan))
                {
                    mentions.Remove(mentions[currentMention]);
                }
            }
		}
Пример #48
0
		public IParse GetHead(IParse parse)
		{
			if (parse == null)
			{
				return null;
			}
			if (parse.IsNounPhrase)
			{
				List<IParse> parts = parse.SyntacticChildren;
				//shallow parse POS
				if (parts.Count > 2)
				{
                    if (parts[1].IsToken && parts[1].SyntacticType == PartsOfSpeech.PossessiveEnding
                        && parts[0].IsNounPhrase && parts[2].IsNounPhrase)
					{
                        return (parts[2]);
					}
				}
				//full parse POS
				if (parts.Count > 1)
				{
                    if (parts[0].IsNounPhrase)
					{
                        List<IParse> childTokens = parts[0].Tokens;
						if (childTokens.Count == 0)
						{
                            Console.Error.WriteLine("PTBHeadFinder: NP " + parts[0] + " with no tokens");
						}
						IParse tok = childTokens[childTokens.Count - 1];
						if (tok.SyntacticType == PartsOfSpeech.PossessiveEnding)
						{
							return null;
						}
					}
				}
				//coordinated nps are their own entities
				if (parts.Count > 1)
				{
					for (int currentPart = 1; currentPart < parts.Count - 1; currentPart++)
					{
                        if (parts[currentPart].IsToken && parts[currentPart].SyntacticType == PartsOfSpeech.CoordinatingConjunction)
						{
							return null;
						}
					}
				}
				//all other NPs
				for (int currentPart = 0; currentPart < parts.Count; currentPart++)
				{
                    if (parts[currentPart].IsNounPhrase)
					{
                        return parts[currentPart];
					}
				}
				return null;
			}
			else
			{
				return null;
			}
		}
Пример #49
0
		private static string GetEntityType(IParse headToken)
		{
			string entityType;
			for (IParse parent = headToken.Parent; parent != null; parent = parent.Parent)
			{
				entityType = parent.EntityType;
				if (entityType != null)
				{
					return entityType;
				}
				if (parent.IsSentence)
				{
					break;
				}
			}
			List<IParse> tokenChildren = headToken.Children;
			int tokenChildCount = tokenChildren.Count;
			if (tokenChildCount > 0)
			{
				IParse tokenChild = tokenChildren[tokenChildCount - 1];
				entityType = tokenChild.EntityType;
				if (entityType != null)
				{
					return entityType;
				}
			}
			return null;
		}
 public IParse GetHead(IParse parse)
 {
     if (parse == null)
     {
         return null;
     }
     if (parse.IsNounPhrase)
     {
         List<IParse> parts = parse.SyntacticChildren;
         //shallow parse POS
         if (parts.Count > 2)
         {
             if (parts[1].IsToken && parts[1].SyntacticType == "POS" && parts[0].IsNounPhrase && parts[2].IsNounPhrase)
             {
                 return (parts[2]);
             }
         }
         //full parse POS
         if (parts.Count > 1)
         {
             if (parts[0].IsNounPhrase)
             {
                 List<IParse> childTokens = parts[0].Tokens;
                 if (childTokens.Count == 0)
                 {
                     System.Console.Error.WriteLine("PTBHeadFinder: NP " + parts[0] + " with no tokens");
                 }
                 IParse tok = childTokens[childTokens.Count - 1];
                 if (tok.SyntacticType == "POS")
                 {
                     return null;
                 }
             }
         }
         //coordinated nps are their own entities
         if (parts.Count > 1)
         {
             for (int currentPart = 1; currentPart < parts.Count - 1; currentPart++)
             {
                 if (parts[currentPart].IsToken && parts[currentPart].SyntacticType == "CC")
                 {
                     return null;
                 }
             }
         }
         //all other NPs
         for (int currentPart = 0; currentPart < parts.Count; currentPart++)
         {
             //System.err.println("PTBHeadFinder.getHead: "+p.getSyntacticType()+" "+p+" parts[currentPart] "+pi+"="+parts[currentPart].getSyntacticType()+" "+parts[currentPart]);
             if (parts[currentPart].IsNounPhrase)
             {
                 return parts[currentPart];
             }
         }
         return null;
     }
     else
     {
         return null;
     }
 }
Пример #51
0
		/// <summary>
        /// Return all noun phrases which are contained by <code>parse</code>.
        /// </summary>
		/// <param name="parse">
        /// The parse in which to find the noun phrases. 
		/// </param>
		/// <returns>
        /// A list of <code>IParse</code> objects which are noun phrases contained by <code>parse</code>.
		/// </returns>
		//protected abstract List getNounPhrases(Parse p);

        public virtual List<IParse> GetNamedEntities(IParse parse)
		{
            return parse.NamedEntities;
		}
 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);
         }
     }
 }
Пример #53
0
 /// <summary>
 /// Constructs context information for the specified mention.
 /// </summary>
 /// <param name="mentionParse">
 /// Mention parse structure for which context is to be constructed.
 /// </param>
 /// <param name="mentionIndex">
 /// mention position in sentence.
 /// </param>
 /// <param name="mentionsInSentence">
 /// Number of mentions in the sentence.
 /// </param>
 /// <param name="mentionsInDocument">
 /// Number of mentions in the document.
 /// </param>
 /// <param name="sentenceIndex">
 /// Sentence number for this mention.
 /// </param>
 /// <param name="nameType">
 /// The named-entity type for this mention.
 /// </param>
 /// <param name="headFinder">
 /// Object which provides head information.
 /// </param>
 /*
 public MentionContext(Parse mentionParse, int mentionIndex, int mentionsInSentence, int mentionsInDocument, int sentenceIndex, String nameType, HeadFinder headFinder) {
 nounLocation = mentionIndex;
 maxNounLocation = mentionsInDocument;
 sentenceNumber = sentenceIndex;
 parse = mentionParse;
 indexSpan = mentionParse.getSpan();
 prevToken = mentionParse.getPreviousToken();
 nextToken = mentionParse.getNextToken();
 head = headFinder.getLastHead(mentionParse);
 List headTokens = head.getTokens();
 tokens = (Parse[]) headTokens.toArray(new Parse[headTokens.size()]);
 basalNextToken = head.getNextToken();
 //System.err.println("MentionContext.init: "+ent+" "+ent.getEntityId()+" head="+head);
 indexHeadSpan = head.getSpan();
 nonDescriptorStart = 0;
 initHeads(headFinder.getHeadIndex(head));
 this.neType= nameType;
 if (getHeadTokenTag().startsWith("NN") && !getHeadTokenTag().startsWith("NNP")) {
 //if (headTokenTag.startsWith("NNP") && neType != null) {
 this.synsets = getSynsetSet(this);
 }
 else {
 this.synsets=Collections.EMPTY_SET;
 }
 gender = GenderEnum.UNKNOWN;
 this.genderProb = 0d;
 number = NumberEnum.UNKNOWN;
 this.numberProb = 0d;
 }
 */
 private void InitializeHeads(int headIndex)
 {
     HeadTokenIndex = headIndex;
     mHeadToken = (IParse) Tokens[HeadTokenIndex];
     HeadTokenText = mHeadToken.ToString();
     HeadTokenTag = mHeadToken.SyntacticType;
     mFirstToken = (IParse) Tokens[0];
     mFirstTokenTag = mFirstToken.SyntacticType;
     mFirstTokenText = mFirstToken.ToString();
 }
Пример #54
0
		protected internal virtual bool IsBasalNounPhrase(IParse nounPhrase)
		{
            return (nounPhrase.NounPhrases.Count == 0);
		}
 public int GetHeadIndex(IParse parse)
 {
     List<IParse> syntacticChildren = parse.SyntacticChildren;
     bool countTokens = false;
     int tokenCount = 0;
     //check for NP -> NN S type structures and return last token before S as head.
     for (int currentSyntacticChild = 0; currentSyntacticChild < syntacticChildren.Count; currentSyntacticChild++)
     {
         IParse syntacticChild = syntacticChildren[currentSyntacticChild];
         //System.err.println("PTBHeadFinder.getHeadIndex "+p+" "+p.getSyntacticType()+" sChild "+sci+" type = "+sc.getSyntacticType());
         if (syntacticChild.SyntacticType.StartsWith("S"))
         {
             if (currentSyntacticChild != 0)
             {
                 countTokens = true;
             }
             else
             {
                 //System.err.println("PTBHeadFinder.getHeadIndex(): NP -> S production assuming right-most head");
             }
         }
         if (countTokens)
         {
             tokenCount += syntacticChild.Tokens.Count;
         }
     }
     List<IParse> tokens = parse.Tokens;
     if (tokens.Count == 0)
     {
         System.Console.Error.WriteLine("PTBHeadFinder.getHeadIndex(): empty tok list for parse " + parse);
     }
     for (int currentToken = tokens.Count - tokenCount - 1; currentToken >= 0; currentToken--)
     {
         IParse token = tokens[currentToken];
         if (!mSkipSet.Contains(token.SyntacticType))
         {
             return currentToken;
         }
     }
     //System.err.println("PTBHeadFinder.getHeadIndex: "+p+" hi="+toks.size()+"-"+tokenCount+" -1 = "+(toks.size()-tokenCount -1));
     return (tokens.Count - tokenCount - 1);
 }
Пример #56
0
        protected internal virtual bool IsPossessive(IParse nounPhrase)
		{
            List<IParse> parts = nounPhrase.SyntacticChildren;
			if (parts.Count > 1)
			{
				if (parts[0].IsNounPhrase)
				{
                    List<IParse> childTokens = parts[0].Tokens;
					IParse token = childTokens[childTokens.Count - 1];
					if (token.SyntacticType == PartsOfSpeech.PossessiveEnding)
					{
						return true;
					}
				}
			}
			if (parts.Count > 2)
			{
                if (parts[1].IsToken && parts[1].SyntacticType == PartsOfSpeech.PossessiveEnding 
                    && parts[0].IsNounPhrase && parts[2].IsNounPhrase)
				{
					return true;
				}
			}
			return false;
		}
        /// <summary>
        /// Returns the bottom-most head of a <code>IParse</code>.  If no
        /// head is available which is a child of <code>parse</code> then
        /// <code>parse</code> is returned. 
        /// </summary>
        public IParse GetLastHead(IParse parse)
        {
            IParse head;
            //System.err.print("EntityFinder.getLastHead: "+p);

            while (null != (head = GetHead(parse)))
            {
                //System.err.print(" -> "+head);
                //if (p.getEntityId() != -1 && head.getEntityId() != p.getEntityId()) {	System.err.println(p+" ("+p.getEntityId()+") -> "+head+" ("+head.getEntityId()+")");      }
                parse = head;
            }
            //System.err.println(" -> null");
            return parse;
        }
Пример #58
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MockInstrumenter"/> class.
        /// </summary>
        /// <param name="parsers">The parsers.</param>
        public MockInstrumenter(IParse[] parsers)
            : base(parsers)
		{
		}
Пример #59
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileCopyInstrumenter"/> class.
        /// </summary>
        /// <param name="parsers">The parsers.</param>
		public FileCopyInstrumenter(IParse[] parsers) : base(parsers)
		{
		}
 private static bool IsPartOfName(IParse nounPhrase)
 {
     string entityType;
     for (IParse parent = nounPhrase.Parent; parent != null; parent = parent.Parent)
     {
         entityType = parent.EntityType;
         //System.err.println("AbstractMentionFinder.isPartOfName: entityType="+entityType);
         if (entityType != null)
         {
             //System.err.println("npSpan = "+np.getSpan()+" parentSpan="+parent.getSpan());
             if (!nounPhrase.Span.Contains(parent.Span))
             {
                 return true;
             }
         }
         if (parent.IsSentence)
         {
             break;
         }
     }
     return false;
 }