Opt GetSearchType(PartsOfSpeech pos) { switch (pos) { case Wnlib.PartsOfSpeech.Noun: return IS_A_NOUN; case Wnlib.PartsOfSpeech.Verb: return IS_A_VERB; }; return null; }
/// <summary> /// /// </summary> /// <param name="pos"></param> /// <returns>Return list of option for searching relatedness correspond to pos /// E.g hypo, hyper of noun /// tropo of verb. /// </returns> public static Opt[] GetRelatedness(PartsOfSpeech pos) { switch (pos) { case Wnlib.PartsOfSpeech.Noun: { Opt[] NOUN_RELATEDNESS = new Opt[] { Opt.at(8), //hyper Opt.at(14), //holo Opt.at(19), //mero Opt.at(12) //hypo }; return NOUN_RELATEDNESS; } case Wnlib.PartsOfSpeech.Verb: { Opt[] VERB_RELATEDNESS = new Opt[] { Opt.at(31),//hyper Opt.at(36)//tropo // may be 38 }; return VERB_RELATEDNESS; } case Wnlib.PartsOfSpeech.Adj: { Opt[] ADJECTIVE_RELATEDNESS = new Opt[] { Opt.at(0) }; return ADJECTIVE_RELATEDNESS; } case Wnlib.PartsOfSpeech.Adv: { Opt[] ADVEB_RELATEDNESS = new Opt[] { Opt.at(48) }; return ADVEB_RELATEDNESS; } }; return null; }
/// <summary> /// Gets the relatedness. /// </summary> /// <param name="pos">The pos.</param> /// <returns> /// Return list of option for searching relatedness correspond to pos /// E.g hypo, hyper of noun /// tropo of verb. /// </returns> public static Opt[] GetRelatedness(PartsOfSpeech pos) { switch (pos) { case PartsOfSpeech.Noun: { var nounRelatedness = new[] { Opt.at(8), //hyper Opt.at(14), //holo Opt.at(19), //mero Opt.at(12) //hypo }; return nounRelatedness; } case PartsOfSpeech.Verb: { var verbRelatedness = new[] { Opt.at(31),//hyper Opt.at(36)//tropo // may be 38 }; return verbRelatedness; } case PartsOfSpeech.Adj: { var adjectiveRelatedness = new[] { Opt.at(0) }; return adjectiveRelatedness; } case PartsOfSpeech.Adv: { var advebRelatedness = new[] { Opt.at(48) }; return advebRelatedness; } } return null; }
PartOfSpeech(string s, string n, PartsOfSpeech f) : this(s, n, "", f) { }
public string GetSentenceFragment(string key) { return((PartsOfSpeech.ContainsKey(key)) ? PartsOfSpeech[key] : "unknown"); }
public override bool CanResolve(MentionContext mention) { string tag = mention.HeadTokenTag; return(tag != null && PartsOfSpeech.IsPersOrPossPronoun(tag) && Linker.PluralThirdPersonPronounPattern.IsMatch(mention.HeadTokenText)); }
public override bool CanResolve(MentionContext mention) { return(PartsOfSpeech.IsProperNoun(mention.HeadTokenTag) || mention.HeadTokenTag.StartsWith(PartsOfSpeechStrings.CardinalNumber)); }
PartOfSpeech(string s,string n,PartsOfSpeech f) : this(s,n,"",f) { }
private bool IsName(Context nounPhrase) { return(PartsOfSpeech.IsProperNoun(nounPhrase.HeadTokenTag)); }
public static List <Word> FillTheWordCharacteristics(List <Word> wordsInf, string textData, string wordFromText, PartsOfSpeech partOfSp) { Word word = new Word(); word.WordText = wordFromText; textData.Replace("'", "").Replace(wordFromText, ""); if (partOfSp == PartsOfSpeech.Conjunction) { word.PartOfSpeech = "союз"; } else if (partOfSp == PartsOfSpeech.Predicative) { word.PartOfSpeech = "предикатив"; } wordsInf.Add(word); return(wordsInf); }
internal IEnumerable <WordPartOfSpeechVertex> PartsOfSpeechSpannedBy(ParentElementBuilder parentElement) { IEnumerable <PartOfSpeechBuilder> partsOfSpeechInSubtree = parentElement.GetElementsOfTypeInSubtree <PartOfSpeechBuilder>(); return(PartsOfSpeech.Where(partOfSpeechVertex => partsOfSpeechInSubtree.Contains(partOfSpeechVertex.Model))); }
internal WordPartOfSpeechVertex PartOfSpeechCorrespondingTo(WordContentVertex token) => PartsOfSpeech.Single(partOfSpeech => partOfSpeech.Model == token.Model);
public async Task Location(IDialogContext context, LuisResult result) { string message = ""; string levelOfGeography = ""; Tuple <string, string> subjectTuple; var conversation = context.Activity as Activity; Activity replyToConversation = conversation.CreateReply(message); replyToConversation.Type = "message"; var entities = new List <EntityRecommendation>(result.Entities); int resultCount = EntityHandler.GetResultCount(entities); subjectTuple = EntityHandler.DetermineSubject(entities); string fullSubjectStr = subjectTuple.Item2; if (fullSubjectStr == "B") { replyToConversation.Text = "Sorry, unable to determine what subject you're asking about"; await context.PostAsync(replyToConversation); context.Wait(MessageReceived); return; } string queryTopic = DataSubjects.Topics.First(t => t.Item2 == fullSubjectStr.Substring(1, 2)).Item1; QueryObject _queryObj = new QueryObject(fullSubjectStr); if (entities.Any((entity) => entity.Type == "level_of_geography")) { levelOfGeography = entities.Where(e => e.Type == "level_of_geography") .First().Entity; Parser.ParseLevelOfGeography(levelOfGeography, _queryObj, _dataTypes); if (!_dataTypes.ResolveSuccess) { replyToConversation.Text = $"{_dataTypes.Message}: '{levelOfGeography}'"; await context.PostAsync(replyToConversation); context.Wait(MessageReceived); return; } } if (entities.Any((entity) => entity.Type == "location")) { string locationEntity = entities.Where(e => e.Type == "location") .First().Entity.ToLower(); LevelsOfGeography lg = Parser.ParseLocation(locationEntity, _queryObj); if (lg.ResolveSuccess) { _queryObj.Location = $"{_queryObj.LocationLevel}:{lg.LocationCode}"; } else { replyToConversation.Text = $"{lg.Message}: '{locationEntity}'"; await context.PostAsync(replyToConversation); context.Wait(MessageReceived); return; } } await context.PostAsync(replyToConversation); string apiResponse = await _queryObj.QueryWeb(); var resultObjects = Parser.ParseToObjects(apiResponse, _queryObj); List <JObject> newObjects = new List <JObject>(); try { if (entities.Any(e => e.Type == "ascending")) { newObjects = resultObjects .OrderBy(x => Convert.ToInt32(x[fullSubjectStr])).Take(resultCount).ToList(); for (var i = 0; i < newObjects.Count(); i++) { if (i == 0) { replyToConversation.Text = $"{newObjects[i]["NAME"].ToString().Replace(" ", "%").Split('%')[0]} has the least {subjectTuple.Item1} with {newObjects[i][fullSubjectStr]}. \r\n"; } else if (i == newObjects.Count() - 1) { replyToConversation.Text += $"Finally, {newObjects[i]["NAME"].ToString().Replace(" ","%").Split('%')[0]} has {subjectTuple.Item1} with {newObjects[i][fullSubjectStr]}. "; } else { //randomize conjunctions to make more natural syntax replyToConversation.Text += $"{PartsOfSpeech.GetConjunctiveAdverb()} {newObjects[i]["NAME"].ToString().Replace(" ", "%").Split('%')[0]} with {newObjects[i][fullSubjectStr]}. \r\n"; } } } else if (entities.Any(e => e.Type == "descending")) { newObjects = resultObjects .OrderByDescending(x => Convert.ToInt32(x[fullSubjectStr])).Take(resultCount).ToList(); for (var i = 0; i < newObjects.Count(); i++) { if (i == 0) { replyToConversation.Text = $"{newObjects[i]["NAME"].ToString().Replace(" ", "%").Split('%')[0]} has the most {subjectTuple.Item1} with {newObjects[i][fullSubjectStr]}. \r\n"; } else if (i == newObjects.Count() - 1) { replyToConversation.Text += $"Finally, {newObjects[i]["NAME"].ToString().Replace(" ", "%").Split('%')[0]} has {newObjects[i][fullSubjectStr]}. "; } else { //randomize conjunctions to make more natural syntax replyToConversation.Text += $"{PartsOfSpeech.GetConjunctiveAdverb()} {newObjects[i]["NAME"].ToString().Replace(" ", "%").Split('%')[0]} with {newObjects[i][fullSubjectStr]}. \r\n"; } } } var json = JsonConvert.SerializeObject(newObjects); //replyToConversation.Text = json; } catch (Exception e) { replyToConversation.Text = "Sorry, I ran into an error trying to serialize my response"; Console.WriteLine(e.Message); } await context.PostAsync(replyToConversation); context.Wait(MessageReceived); }
public MyWordInfo(string word, Wnlib.PartsOfSpeech pos) { this.Word=word; this.Pos=pos; this.Sense =0; }
private bool IsCommonNoun(Context nounPhrase) { return(!PartsOfSpeech.IsProperNoun(nounPhrase.HeadTokenTag) && PartsOfSpeech.IsNoun(nounPhrase.HeadTokenTag)); }
/// <summary> /// Returns a string for the specified mention with punctuation, honorifics, designators, and determiners removed. /// </summary> /// <param name="mention"> /// The mention to be stripped. /// </param> /// <returns> /// a normalized string representation of the specified mention. /// </returns> protected internal virtual string StripNounPhrase(Mention.MentionContext mention) { var start = mention.NonDescriptorStart; //start after descriptors var mentionTokens = mention.TokenParses; var end = mention.HeadTokenIndex + 1; if (start == end) { return(null); } //strip determiners if (mentionTokens[start].SyntacticType == PartsOfSpeechStrings.Determiner) { start++; } if (start == end) { return(null); } //get to first NNP for (var index = start; index < end; index++) { var type = mentionTokens[start].SyntacticType; if (PartsOfSpeech.IsProperNoun(type)) { break; } start++; } if (start == end) { return(null); } if (start + 1 != end) { // don't do this on head words, to keep "U.S." //strip off honorifics in begining if (Linker.HonorificsPattern.IsMatch(mentionTokens[start].ToString())) { start++; } if (start == end) { return(null); } //strip off and honorifics on the end if (Linker.DesignatorsPattern.IsMatch(mentionTokens[mentionTokens.Length - 1].ToString())) { end--; } } if (start == end) { return(null); } var strip = new StringBuilder(); for (var i = start; i < end; i++) { strip.Append(mentionTokens[i].ToString()).Append(" "); } return(strip.ToString().Trim()); }
private bool IsPronoun(Context nounPhrase) { return(PartsOfSpeech.IsPersOrPossPronoun(nounPhrase.HeadTokenTag)); }
PartOfSpeech(string s,string n, string c,PartsOfSpeech f) { sy = s; nm = n; cl = c; flg = f; id = uniq++; parts[s] = this; if (c=="") parts[nm] = this; }
private string GetIndexFilePath(PartsOfSpeech n) { return(_path + _index + n.ToDescriptionString()); }
public static PartOfSpeech of(PartsOfSpeech f) { if (f==PartsOfSpeech.Noun) return PartOfSpeech.of("noun"); if (f==PartsOfSpeech.Verb) return PartOfSpeech.of("verb"); if (f==PartsOfSpeech.Adj) return PartOfSpeech.of("adj"); if (f==PartsOfSpeech.Adv) return PartOfSpeech.of("adv"); return null; // unknown or not unique }
private static CheckBox ConvertToCheckBox(PartsOfSpeech speechPart, bool status) => new CheckBox { Text = speechPart.ToString(), Checked = status, AutoSize = true };
public static int GetSynsetIndex(string word, PartsOfSpeech pos) { word=word.ToLower() ; //word=RemoveBadChars (word); Wnlib.Index index=Wnlib.Index.lookup( word, PartOfSpeech.of(pos) ); if( index == null ) { Wnlib.MorphStr morphs=new Wnlib.MorphStr(word, Wnlib.PartOfSpeech.of( pos ) ); string morph = ""; while( ( morph = morphs.next() ) != null ) { index = Wnlib.Index.lookup(morph, Wnlib.PartOfSpeech.of(pos) ); if( index != null ) break; } } if (index == null) return -1; else return 0; }
public bool HasWritePartOfSpeech(string name, PartsOfSpeech partsOfSpeech) { var firstPartOfName = _nameSplitter.Split(name).FirstOrDefault(); var partOfSpeeches = _wordLookUp.FindWordPartOfSpeeches(firstPartOfName.ToLower()); return partOfSpeeches.Contains(partsOfSpeech); }