/// <summary> /// Parses sentence. /// </summary> /// <param name="sentence"></param> /// <returns></returns> public override NotenizerNote Parse(NotenizerSentence sentence) { NotenizerNote note = new NotenizerNote(sentence); foreach (NotenizerDependency dependencyLoop in sentence.Structure.Dependencies) { if (dependencyLoop.Relation.IsNominalSubject() && !((note.Structure.CompressedDependencies.ContainsKey(GrammaticalConstants.NominalSubject) && note.Structure.CompressedDependencies[GrammaticalConstants.NominalSubject].Any(x => x.Key == dependencyLoop.Key)) || (note.Structure.CompressedDependencies.ContainsKey(GrammaticalConstants.NominalSubjectPassive) && note.Structure.CompressedDependencies[GrammaticalConstants.NominalSubjectPassive].Any(x => x.Key == dependencyLoop.Key)))) { NotePart notePart = new NotePart(sentence); NoteParticle nsubj = new NoteParticle(dependencyLoop, TokenType.Dependent); notePart.Add(nsubj); String pos = dependencyLoop.Governor.POS.Tag; if (POSConstants.NounLikePOS.Contains(pos)) { NotenizerDependency compound = sentence.Structure.GetDependencyByShortName( dependencyLoop, ComparisonType.DependentToGovernor, GrammaticalConstants.CompoudModifier); if (compound != null) { NoteParticle compoundObj = new NoteParticle(compound, TokenType.Dependent); notePart.Add(compoundObj); } NotenizerDependency aux = sentence.Structure.GetDependencyByShortName( dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.AuxModifier, GrammaticalConstants.AuxModifierPassive); if (aux != null) { NoteParticle auxObj = new NoteParticle(aux, TokenType.Dependent); notePart.Add(auxObj); } NotenizerDependency cop = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.Copula); if (cop != null) { NoteParticle copObj = new NoteParticle(cop, TokenType.Dependent); notePart.Add(copObj); } List<NotenizerDependency> conjuctions = sentence.Structure.GetDependenciesByShortName( dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.Conjuction); String specific = String.Empty; if (conjuctions != null && conjuctions.Count > 0) { List<NotenizerDependency> filteredConjs = FilterByPOS(conjuctions, POSConstants.ConjustionPOS); foreach (NotenizerDependency filteredConjLoop in filteredConjs) { NotenizerDependency cc = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.CoordinatingConjuction); if (cc.Dependent.Word == filteredConjLoop.Relation.Specific && sentence.Structure.DependencyIndex(filteredConjLoop) > sentence.Structure.DependencyIndex(cc)) { NoteParticle ccObj = new NoteParticle(cc, TokenType.Dependent); NoteParticle filteredConjObj = new NoteParticle(filteredConjLoop, TokenType.Dependent); notePart.Add(ccObj); notePart.Add(filteredConjObj); } } } // <== NMODS ==> List<NotenizerDependency> nmodsList = sentence.Structure.GetDependenciesByShortName( dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.NominalModifier); if (nmodsList != null && nmodsList.Count > 0) { NotenizerDependency first = nmodsList.First(); NotenizerDependency neg = sentence.Structure.GetDependencyByShortName( first, ComparisonType.DependentToGovernor, GrammaticalConstants.NegationModifier); if (neg == null) { NoteParticle firstObj = new NoteParticle(first.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + first.Dependent.Word, first, TokenType.Dependent); notePart.Add(firstObj); } else { NoteParticle negObj = new NoteParticle(neg, TokenType.Dependent); NoteParticle firstObj = new NoteParticle(first.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + first.Dependent.Word, first, TokenType.Dependent); notePart.Add(negObj); notePart.Add(firstObj); } // second nmod depending on first one NotenizerDependency nmodSecond = sentence.Structure.GetDependencyByShortName( first, ComparisonType.DependentToGovernor, GrammaticalConstants.NominalModifier); if (nmodSecond != null) { neg = sentence.Structure.GetDependencyByShortName( first, ComparisonType.GovernorToGovernor, GrammaticalConstants.NegationModifier); if (neg == null) { NoteParticle secondObj = new NoteParticle(nmodSecond.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + nmodSecond.Dependent.Word, nmodSecond, TokenType.Dependent); notePart.Add(secondObj); } else { NoteParticle negObj = new NoteParticle(neg, TokenType.Dependent); NoteParticle secondObj = new NoteParticle(nmodSecond.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + nmodSecond.Dependent.Word, nmodSecond, TokenType.Dependent); notePart.Add(negObj); notePart.Add(secondObj); } } } else { // <== AMODS ==> NotenizerDependency amod1 = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.DependentToGovernor, GrammaticalConstants.AdjectivalModifier); // <== AMODS ==> NotenizerDependency amod2 = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.AdjectivalModifier); if (amod1 != null || amod2 != null) { if (amod1 != null) { NoteParticle amod1Obj = new NoteParticle(amod1, TokenType.Dependent); notePart.Add(amod1Obj); } if (amod2 != null) { NoteParticle amod2Obj = new NoteParticle(amod2, TokenType.Dependent); notePart.Add(amod2Obj); } } else { // <== NUMMODS ==> NotenizerDependency nummod1 = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.DependentToGovernor, GrammaticalConstants.NumericModifier); // <== NUMMODS ==> NotenizerDependency nummod2 = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.NumericModifier); if (nummod1 != null) { NoteParticle nummod1Obj = new NoteParticle(nummod1, TokenType.Dependent); notePart.Add(nummod1Obj); } if (nummod2 != null) { NoteParticle nummod2Obj = new NoteParticle(nummod2, TokenType.Dependent); notePart.Add(nummod2Obj); } } } NoteParticle governorObj = new NoteParticle(dependencyLoop, TokenType.Governor); notePart.Add(governorObj); } else if (POSConstants.VerbLikePOS.Contains(pos)) { NoteParticle gov = new NoteParticle(dependencyLoop, TokenType.Governor); notePart.Add(gov); NotenizerDependency dobj = sentence.Structure.GetDependencyByShortName(dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.DirectObject); if (dobj != null) { NoteParticle dobjObj = new NoteParticle(dobj, TokenType.Dependent); notePart.Add(dobjObj); NotenizerDependency neg = sentence.Structure.GetDependencyByShortName(dobj, ComparisonType.DependentToGovernor, GrammaticalConstants.NegationModifier); if (neg != null) { NoteParticle negObj = new NoteParticle(neg, TokenType.Dependent); notePart.Add(negObj); } } NotenizerDependency aux = sentence.Structure.GetDependencyByShortName( dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.AuxModifier, GrammaticalConstants.AuxModifierPassive); if (aux != null) { NoteParticle auxObj = new NoteParticle(aux, TokenType.Dependent); notePart.Add(auxObj); } // <== NMODS ==> List<NotenizerDependency> nmodsList = sentence.Structure.GetDependenciesByShortName( dependencyLoop, ComparisonType.GovernorToGovernor, GrammaticalConstants.NominalModifier); if (nmodsList != null && nmodsList.Count > 0) { NotenizerDependency first = nmodsList.First(); NotenizerDependency neg = sentence.Structure.GetDependencyByShortName(first, ComparisonType.DependentToGovernor, GrammaticalConstants.NegationModifier); if (neg == null) { NoteParticle firstObj = new NoteParticle(first.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + first.Dependent.Word, first, TokenType.Dependent); notePart.Add(firstObj); } else { NoteParticle negObj = new NoteParticle(neg, TokenType.Dependent); NoteParticle firstObj = new NoteParticle(first.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + first.Dependent.Word, first, TokenType.Dependent); notePart.Add(firstObj); notePart.Add(negObj); } // second nmod depending on first one NotenizerDependency nmodSecond = sentence.Structure.GetDependencyByShortName(first, ComparisonType.DependentToGovernor, GrammaticalConstants.NominalModifier); if (nmodSecond != null) { neg = sentence.Structure.GetDependencyByShortName(first, ComparisonType.GovernorToGovernor, GrammaticalConstants.NegationModifier); if (neg == null) { NoteParticle secondObj = new NoteParticle(nmodSecond.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + nmodSecond.Dependent.Word, nmodSecond, TokenType.Dependent); notePart.Add(secondObj); } else { NoteParticle negObj = new NoteParticle(neg, TokenType.Dependent); NoteParticle secondObj = new NoteParticle(nmodSecond.Relation.AdjustedSpecific + NotenizerConstants.WordDelimeter + nmodSecond.Dependent.Word, nmodSecond, TokenType.Dependent); notePart.Add(secondObj); notePart.Add(negObj); } } } } note.Add(notePart); } } return note; }
/// <summary> /// Fully clones note part object. /// </summary> /// <returns></returns> public NotePart Clone() { NotePart clonedNotePart = new NotePart(this._originalSentence); foreach (NoteParticle noteParticleLoop in this.InitializedNoteParticles) clonedNotePart.Add(noteParticleLoop); return clonedNotePart; }
/// <summary> /// Creates note parts from edited note. /// </summary> /// <returns></returns> private List<NotePart> CreateNoteParts() { NotenizerAdvancedLabel label; List<NotePart> noteParts = new List<NotePart>(); NotePart notePart = new NotePart(this._note.OriginalSentence); noteParts.Add(notePart); for (int i = 0; i < this._flowLayoutPanelActive.Controls.Count; i++) { label = (this._flowLayoutPanelActive.Controls[i] as NotenizerAdvancedLabel); if (label.RepresentMode == RepresentMode.SentenceEnd) { notePart = new NotePart(_note.OriginalSentence); noteParts.Add(notePart); continue; } SetPositionAddToNotePart(label.Dependency, i, notePart); } if (notePart.InitializedNoteParticles.Count == 0) noteParts.Remove(notePart); return noteParts; }
/// <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)); }
/// <summary> /// Apply button click event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ApplyButton_Click(Object sender, EventArgs e) { this._noteParts = CreateNoteParts(); this._andParserNotePart = CreateAndParserNotePart(); this.DialogResult = DialogResult.OK; }
/// <summary> /// Create Note Part from edited and-note. /// </summary> /// <returns></returns> private NotePart CreateAndParserNotePart() { int depCounter = 0; NotenizerAdvancedLabel label; NotePart notePart = new NotePart(_note.OriginalSentence); for (int i = 0; i < this._advancedFlowLayoutPanelAndParserActive.Controls.Count; i++) { label = this._advancedFlowLayoutPanelAndParserActive.Controls[i] as NotenizerAdvancedLabel; if (label.RepresentMode == RepresentMode.AndSet) { _andSetsPosition = i; continue; } SetPositionAddToNotePart(label.Dependency, depCounter, notePart); depCounter++; } return notePart; }
/// <summary> /// Splits note into sentences. /// </summary> /// <param name="sentenceEnd"></param> public void SplitToSentences(int sentenceEnd) { List<NotePart> parts = new List<NotePart>(); NotePart notePart = new NotePart(_originalSentence); if (sentenceEnd > _noteParts[0].InitializedNoteParticles.Count) sentenceEnd = _noteParts[0].InitializedNoteParticles.Count - 1; if (sentenceEnd < 0) return; notePart.Add(_noteParts[0].InitializedNoteParticles.GetRange(0, sentenceEnd)); parts.Add(notePart); _text = String.Empty; _noteParts = new List<NotePart>(); Add(parts); }
/// <summary> /// Splits sentence to sentences by indexes of sentences last words. /// </summary> /// <param name="endsIndices"></param> public void SplitToSentences(List<int> endsIndices) { int lastIndex = 0; List<NotePart> parts = new List<NotePart>(); foreach (int indexLoop in endsIndices) { // TODO: docasna podmienka, lebo nie je doriesene rozoznavanie medzi sadami pravidiel // a vzdy sa zoberie prva, preto nemusi sediet pre niektoru vetu a tym padom by to tu // padlo na ArgumentOutOfRangeException if (indexLoop - lastIndex >= _noteParts[0].InitializedNoteParticles.Count) return; if (lastIndex > _noteParts[0].InitializedNoteParticles.Count) lastIndex = _noteParts[0].InitializedNoteParticles.Count - 1; if (indexLoop < lastIndex) return; NotePart notePart = new NotePart(_originalSentence); notePart.Add(_noteParts[0].InitializedNoteParticles.GetRange(lastIndex, indexLoop - lastIndex)); lastIndex = indexLoop; parts.Add(notePart); } _text = String.Empty; _noteParts = new List<NotePart>(); Add(parts); }
/// <summary> /// Adds note part to this note. /// </summary> /// <param name="notePart"></param> public void Add(NotePart notePart) { _text += notePart.AdjustedValue + NotenizerConstants.WordDelimeter; _noteParts.Add(notePart); foreach (NoteParticle notePartNoteParticleLoop in notePart.InitializedNoteParticles) { this._structure.CompressedDependencies.Add(notePartNoteParticleLoop.NoteDependency); this._structure.Dependencies.Add(notePartNoteParticleLoop.NoteDependency); } }
/// <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); } }
/// <summary> /// Applies rule. /// Parses sentence by applied rule. /// </summary> /// <param name="sentence">Sentence to apply rule to</param> /// <param name="rule">Rule for parsing to apply</param> /// <returns></returns> public NotenizerNote ApplyRule(NotenizerSentence sentence, NotenizerRule rule) { NotenizerNote note = new NotenizerNote(sentence); NotePart notePart = new NotePart(sentence); foreach (NotenizerDependency ruleLoop in rule.Structure.Dependencies) { ApplyRule(sentence, ruleLoop, notePart); } note.Add(notePart); if (rule is NotenizerNoteRule) ApplyRule(note, rule as NotenizerNoteRule); else if (rule is NotenizerAndRule) ApplyRule(note, rule as NotenizerAndRule); //note.Note = rule.Note; note.Structure = rule.Structure; return note; }