Example #1
0
        /// <summary>
        /// Compares dependencies.
        /// </summary>
        /// <param name="source">Source dependency</param>
        /// <param name="dest">Destination depenedency</param>
        /// <param name="dependeciesAndWordsCount">Number of dependencies and words</param>
        /// <returns></returns>
        public double Compare(NotenizerDependency source, NotenizerDependency dest, int dependeciesAndWordsCount)
        {
            try
            {
                _matchRating = 0;
                _oneComparisonRating = NotenizerConstants.MaxMatchValue / Count;

                foreach (Comparsion<bool> boolWordComparsionLoop in _boolWordsComparsions)
                {
                    if (boolWordComparsionLoop.Run(source.Governor, dest.Governor))
                        _matchRating += _oneComparisonRating;

                    if (boolWordComparsionLoop.Run(source.Dependent, dest.Dependent))
                        _matchRating += _oneComparisonRating;
                }

                foreach (Comparsion<double> doubleWordsComparsionLoop in _doubleWordsComparsions)
                {
                    _matchRating += doubleWordsComparsionLoop.Run(source.Governor, dest.Governor, _oneComparisonRating, dependeciesAndWordsCount);
                    _matchRating += doubleWordsComparsionLoop.Run(source.Dependent, dest.Dependent, _oneComparisonRating, dependeciesAndWordsCount);
                }

                return _matchRating;
            }
            catch (Exception ex)
            {
                throw new Exception("Error comnparing two dependencies." + Environment.NewLine + Environment.NewLine + ex.Message);
            }
        }
Example #2
0
 public NoteParticle(NotenizerDependency dependency)
 {
     _tokenType = dependency.TokenType;
     _noteDependency = dependency.Clone();
     _noteWord = dependency.CorrespondingWord;
     //_noteWordValue = MakeWordConsiderRelation(_noteWord, _noteDependency.Relation);
     _noteWordValue = _noteWord.Word;
 }
Example #3
0
 public NoteParticle(String noteWordValue, NotenizerDependency dependency, TokenType tokenType)
 {
     _tokenType = tokenType;
     _noteDependency = dependency.Clone();
     _noteDependency.TokenType = tokenType;
     _noteWordValue = noteWordValue;
     _noteWord = tokenType == TokenType.Dependent ? dependency.Dependent : dependency.Governor;
 }
        public NotenizerAdvancedLabel(NotenizerDependency dependency, Font font)
            : base(font)
        {
            this._dependency = dependency;
            this._representMode = RepresentMode.Dependency;

            InitializeComponent();
            Init();
        }
Example #5
0
        public NoteParticle(NotenizerDependency dependency, TokenType tokenType, bool considerRelationInWordValueMaking = false)
        {
            if (tokenType == TokenType.Unidentified)
                throw new Exception("Can't make NoteParticle from token of type " + tokenType.ToString());

            _tokenType = tokenType;
            _noteDependency = dependency.Clone();
            _noteDependency.TokenType = tokenType;
            _noteWord = _tokenType == TokenType.Dependent ? dependency.Dependent : dependency.Governor;
            _noteWordValue = considerRelationInWordValueMaking ? MakeWordConsiderRelation(_noteWord, _noteDependency.Relation) : _noteWord.Word; ;
        }
Example #6
0
 public static double CalculateClosenessDependencies(NotenizerDependency firstDep, NotenizerDependency secondDep, double comparisonValue, int count)
 {
     return CalculateCloseness(firstDep.Position, secondDep.Position, comparisonValue, count);
 }
Example #7
0
        /// <summary>
        /// Gets depeendencies from sentence.
        /// </summary>
        /// <param name="annotation"></param>
        /// <returns></returns>
        private NotenizerDependencies GetDepencencies(Annotation annotation)
        {
            Tree tree;
            NotenizerDependency dep;
            GrammaticalStructure gramStruct;
            NotenizerDependencies dependencies;
            NotenizerDependency nsubjComplement;
            TreebankLanguagePack treeBankLangPack;
            java.util.Collection typedDependencies;
            GrammaticalStructureFactory gramStructFact;

            tree = annotation.get(typeof(TreeCoreAnnotations.TreeAnnotation)) as Tree;
            treeBankLangPack = new PennTreebankLanguagePack();
            gramStructFact = treeBankLangPack.grammaticalStructureFactory();
            gramStruct = gramStructFact.newGrammaticalStructure(tree);
            typedDependencies = gramStruct.typedDependenciesCollapsed();
            dependencies = new NotenizerDependencies();

            foreach (TypedDependency typedDependencyLoop in (typedDependencies as java.util.ArrayList))
            {
                dep = new NotenizerDependency(typedDependencyLoop);
                dependencies.Add(dep);

                if (dep.Relation.IsNominalSubject())
                {
                    nsubjComplement = new NotenizerDependency(typedDependencyLoop);
                    nsubjComplement.TokenType = dep.TokenType == TokenType.Dependent ? TokenType.Governor : TokenType.Dependent;
                    dependencies.Add(nsubjComplement);
                }
            }

            return dependencies;
        }
Example #8
0
        /// <summary>
        /// Create dependencies from deocument.
        /// </summary>
        /// <param name="dbEntry"></param>
        /// <param name="noteFieldName"></param>
        /// <returns></returns>
        private static NotenizerDependencies ParseDependencies(BsonDocument dbEntry, String noteFieldName)
        {
            int position;
            TokenType tokenType;
            NotenizerWord governor;
            NotenizerWord dependent;
            BsonDocument governorDoc;
            BsonDocument dependantDoc;
            NotenizerRelation relation;
            ComparisonType comparisonType;
            NotenizerDependency dependency;
            NotenizerDependencies dependencies = new NotenizerDependencies();
            // foreach note dependency
            foreach (BsonDocument documentLoop in dbEntry[noteFieldName].AsBsonArray)
            {
                relation = new NotenizerRelation(documentLoop[DBConstants.RelationNameFieldName].AsString);

                // foreach dependency in array of dependencies with same relation name
                foreach (BsonDocument dependencyDocLoop in documentLoop[DBConstants.DependenciesFieldName].AsBsonArray)
                {
                    governorDoc = dependencyDocLoop[DBConstants.GovernorFieldName].AsBsonDocument;
                    dependantDoc = dependencyDocLoop[DBConstants.DependentFieldName].AsBsonDocument;
                    position = dependencyDocLoop[DBConstants.PositionFieldName].AsInt32;
                    comparisonType = dependencyDocLoop.GetValue(DBConstants.ComparisonTypeFieldName, ComparisonType.Unidentified).AsInt32.ToEnum<ComparisonType>();
                    tokenType = dependencyDocLoop.GetValue(DBConstants.TokenTypeFieldName, TokenType.Unidentified).AsInt32.ToEnum<TokenType>();

                    governor = new NotenizerWord(
                        governorDoc[DBConstants.POSFieldName].AsString,
                        governorDoc[DBConstants.IndexFieldName].AsInt32,
                        governorDoc[DBConstants.LemmaFieldName].AsString,
                        governorDoc[DBConstants.NERFieldName].AsString);

                    dependent = new NotenizerWord(
                        dependantDoc[DBConstants.POSFieldName].AsString,
                        dependantDoc[DBConstants.IndexFieldName].AsInt32,
                        dependantDoc[DBConstants.LemmaFieldName].AsString,
                        dependantDoc[DBConstants.NERFieldName].AsString);

                    dependency = new NotenizerDependency(governor, dependent, relation, position, comparisonType, tokenType);

                    dependencies.Add(dependency);
                }
            }

            return dependencies;
        }
Example #9
0
 /// <summary>
 /// Sets position of dependnecy and adds it to note part.
 /// </summary>
 /// <param name="dep"></param>
 /// <param name="position"></param>
 /// <param name="destionationNotePart"></param>
 private void SetPositionAddToNotePart(NotenizerDependency dep, int position, NotePart destionationNotePart)
 {
     dep.Position = position;
     destionationNotePart.Add(new NoteParticle(dep));
 }
Example #10
0
        /// <summary>
        /// Finds depdendcy by rule's dependency.
        /// </summary>
        /// <param name="ruleDependency"></param>
        /// <returns></returns>
        public NotenizerDependency FindDependency(NotenizerDependency ruleDependency)
        {
            if (_compressedDependencies.ContainsKey(ruleDependency.Relation.ShortName))
            {
                foreach (NotenizerDependency dependencyLoop in _compressedDependencies[ruleDependency.Relation.ShortName])
                {
                    if (dependencyLoop.Governor.POS.Type == ruleDependency.Governor.POS.Type
                        && dependencyLoop.Dependent.POS.Type == ruleDependency.Dependent.POS.Type)
                        return dependencyLoop;
                }
            }

            return null;
        }
Example #11
0
        /// <summary>
        /// Index of dependnecy.
        /// </summary>
        /// <param name="dependency"></param>
        /// <returns></returns>
        public int DependencyIndex(NotenizerDependency dependency)
        {
            for (int i = 0; i < _dependencies.Count; i++)
            {
                if (dependency.Dependent.Word == _dependencies[i].Dependent.Word
                    && dependency.Governor.Word == _dependencies[i].Governor.Word
                    && dependency.Relation.ShortName == _dependencies[i].Relation.ShortName
                    && dependency.Dependent.Index == _dependencies[i].Dependent.Index
                    && dependency.Governor.Index == _dependencies[i].Governor.Index)
                    return i;
            }

            throw new Exception("Sentence doesn't contain dependency: " + dependency.ToString());
        }
Example #12
0
        /// <summary>
        /// Fully clones dependency.
        /// </summary>
        /// <returns></returns>
        public NotenizerDependency Clone()
        {
            NotenizerDependency clonedDep;

            if (this._originalDependency == null)
                clonedDep = new NotenizerDependency(this._governor, this._dependent, this._relation, this._position, this._comparisonType, this._tokenType);
            else
                clonedDep = new NotenizerDependency(this._originalDependency);

            clonedDep.Position = this._position;
            clonedDep.TokenType = this._tokenType;
            clonedDep.ComparisonType = this._comparisonType;

            return clonedDep;
        }
Example #13
0
        /// <summary>
        /// Compares two dependencies
        /// </summary>
        /// <param name="mainDependency">Main dependency</param>
        /// <param name="secondaryDependency">Second dependency</param>
        /// <param name="comparisonType">Comparison type</param>
        /// <returns></returns>
        private bool CompareDependencies(NotenizerDependency mainDependency, NotenizerDependency secondaryDependency, ComparisonType comparisonType)
        {
            switch (comparisonType)
            {
                case ComparisonType.DependentToDependant:
                    return mainDependency.Dependent == secondaryDependency.Dependent;

                case ComparisonType.GovernorToGovernor:
                    return mainDependency.Governor == secondaryDependency.Governor;

                case ComparisonType.DependentToGovernor:
                    return mainDependency.Dependent == secondaryDependency.Governor;

                case ComparisonType.GovernorToDependant:
                    return mainDependency.Governor == secondaryDependency.Dependent;
            }

            throw new Exception("Error in CompareDependencies. Unidentified Comparison type.");
        }
Example #14
0
        /// <summary>
        /// Gets first or null dependency by short name.
        /// </summary>
        /// <param name="dependencyShortName"></param>
        /// <param name="searchResult"></param>
        /// <returns></returns>
        public NotenizerDependency GetDependencyByShortName(NotenizerDependency mainDependency, ComparisonType comparisonType, params String[] dependencyShortNames)
        {
            foreach (String dependencyShortNameLoop in dependencyShortNames)
            {
                if (_compressedDependencies.ContainsKey(dependencyShortNameLoop))
                {
                    foreach (NotenizerDependency dependencyLoop in _compressedDependencies[dependencyShortNameLoop])
                    {
                        if (CompareDependencies(mainDependency, dependencyLoop, comparisonType))
                        {
                            dependencyLoop.ComparisonType = comparisonType;
                            return dependencyLoop;
                        }
                    }
                }
            }

            return null;
        }
Example #15
0
        /// <summary>
        /// Get all dependencies by short name
        /// </summary>
        /// <param name="mainDependency">Dependency to compare with</param>
        /// <param name="comparisonType">Comparison type</param>
        /// <param name="dependencyShortNames">Short names</param>
        /// <returns></returns>
        public List<NotenizerDependency> GetDependenciesByShortName(NotenizerDependency mainDependency, ComparisonType comparisonType, params String[] dependencyShortNames)
        {
            List<NotenizerDependency> dependencies = new List<NotenizerDependency>();

            foreach (String dependencyShortNameLoop in dependencyShortNames)
            {
                if (_compressedDependencies.ContainsKey(dependencyShortNameLoop))
                {
                    foreach (NotenizerDependency dependencyLoop in _compressedDependencies[dependencyShortNameLoop])
                    {
                        if (CompareDependencies(mainDependency, dependencyLoop, comparisonType))
                        {
                            dependencyLoop.ComparisonType = comparisonType;
                            dependencies.Add(dependencyLoop);
                        }
                    }
                }
            }

            return dependencies;
        }
Example #16
0
 public static bool SamePosition(NotenizerDependency firstD, NotenizerDependency secondD)
 {
     return firstD.Position == secondD.Position;
 }
Example #17
0
 public NoteParticle(String noteWordValue, NotenizerWord noteWord, NotenizerDependency noteDependency)
 {
     _noteWordValue = noteWordValue;
     _noteWord = noteWord;
     _noteDependency = noteDependency.Clone();
 }
Example #18
0
        /// <summary>
        /// Applies rule.
        /// Parses sentence by applied rule and part of note of original sentence.
        /// </summary>
        /// <param name="sentence">Sentence to apply rule to</param>
        /// <param name="rule">Rule for parsing to apply</param>
        /// <param name="notePart">Part of note</param>
        private void ApplyRule(NotenizerSentence sentence, NotenizerDependency rule, NotePart notePart)
        {
            NotenizerDependency dependency = null;// = sentence.FindDependency(rule);
            double match = 0.0;
            double currentMatch = 0.0;

            foreach (NotenizerDependency dependencyLoop in sentence.Structure.FindDependencies(rule))
            {
                if (dependencyLoop == null)
                    continue;

                if ((currentMatch = _comparsionManager.Compare(rule, dependencyLoop, sentence.Structure.Dependencies.Count)) > match)
                {
                    match = currentMatch;
                    dependency = dependencyLoop;
                }
            }

            if (dependency != null)
            {
                NoteParticle dependencyObj = new NoteParticle(dependency, rule.TokenType, rule.Position);
                notePart.Add(dependencyObj);
            }
        }
Example #19
0
 /// <summary>
 /// Find depdendencies by rule's dependency.
 /// </summary>
 /// <param name="ruleDependency"></param>
 /// <returns></returns>
 public IEnumerable<NotenizerDependency> FindDependencies(NotenizerDependency ruleDependency)
 {
     if (_compressedDependencies.ContainsKey(ruleDependency.Relation.ShortName))
     {
         foreach (NotenizerDependency dependencyLoop in _compressedDependencies[ruleDependency.Relation.ShortName])
         {
             if (dependencyLoop.Governor.POS.Type == ruleDependency.Governor.POS.Type
                 && dependencyLoop.Dependent.POS.Type == ruleDependency.Dependent.POS.Type)
                 yield return dependencyLoop;
         }
     }
 }