public static double GetPixelCorrespondingRatio(Word w1, Word w2, WordRelation relation) { switch (relation) { case WordRelation.InLine: var y1 = w1.BoundingRect.Top; var y2 = w1.BoundingRect.Bottom; var y3 = w2.BoundingRect.Top; var y4 = w2.BoundingRect.Bottom; if (y1 > y3) { return((double)(y4 - y1) / Math.Min(w1.BoundingRect.Height, w2.BoundingRect.Height)); } return((double)(y2 - y3) / Math.Min(w1.BoundingRect.Height, w2.BoundingRect.Height)); case WordRelation.InColumn: var x1 = w1.BoundingRect.Left; var x2 = w1.BoundingRect.Right; var x3 = w2.BoundingRect.Left; var x4 = w2.BoundingRect.Right; if (x1 > x3) { return((double)(x4 - x1) / Math.Min(w1.BoundingRect.Width, w2.BoundingRect.Width)); } return((double)(x2 - x3) / Math.Min(w1.BoundingRect.Width, w2.BoundingRect.Width)); default: throw new ArgumentOutOfRangeException(nameof(relation), relation, null); } }
internal void Merge(WordRelation Relationship) { if (Relationship != null) { foreach (KeyValuePair <String, WordItem> Item in Relationship.Items) { Add(Item.Value); } } }
private void populateSynonyms() { if (!isSynonymPopulated) { WordRelation relation = new WordRelation(); List <string> words = relation.getSynonymsForWord(CurrentWord.Name); populateStack(stackSynonym, words); isSynonymPopulated = true; } else { depopulateStack(stackSynonym); WordRelation relation = new WordRelation(); List <string> words = relation.getSynonymsForWord(CurrentWord.Name); populateStack(stackSynonym, words); } }
public virtual List expand(string text) { string inputText = this.simplifyChars(text); CharTokenizer charTokenizer = new CharTokenizer(); charTokenizer.setWhitespaceSymbols(" \t\n\r"); charTokenizer.setSingleCharSymbols(""); charTokenizer.setPrepunctuationSymbols("\"'`({["); charTokenizer.setPostpunctuationSymbols("\"'`.,:;!?(){}[]"); charTokenizer.setInputText(inputText); Utterance utterance = new Utterance(charTokenizer); Relation relation; if ((relation = utterance.getRelation("Token")) == null) { string text2 = "token relation does not exist"; throw new IllegalStateException(text2); } this.wordRelation = WordRelation.createWordRelation(utterance, this); this.tokenItem = relation.getHead(); while (this.tokenItem != null) { FeatureSet features = this.tokenItem.getFeatures(); string @string = features.getString("name"); this.tokenToWords(@string); this.tokenItem = this.tokenItem.getNext(); } ArrayList arrayList = new ArrayList(); for (Item item = utterance.getRelation("Word").getHead(); item != null; item = item.getNext()) { if (!String.instancehelper_isEmpty(item.toString())) { string text3 = item.toString(); object _ref = "#"; CharSequence charSequence = CharSequence.Cast(_ref); if (!String.instancehelper_contains(text3, charSequence)) { arrayList.add(item.toString()); } } } return(arrayList); }
public string ToJson() { return(string.Format("{0} ({1}) {2}.", Word, SpeechPart, WordRelation.ToString().ToLower().Substring(0, 3))); }
private bool HasStrongRelation(Word w1, Word w2, WordRelation relation) { var ratio = GetPixelCorrespondingRatio(w1, w2, relation); return(ratio > 0.7); }
public override sealed async Task GetRelatedWords(string noun, WordRelation relation) => SetLookedUp(relation switch
/// <summary>The word currently being used in Datamuse queries to select Potential alternates</summary> //private protected string PivotWord { get; set; } //internal void SetPivot(string word) //{ // PivotWord = word; // GetSynonymsFor(PivotWord); //} public abstract Task GetRelatedWords(string word, WordRelation relation);