public async static Task GetTextAsync(string uri) { var image = Image.FromUri(uri); var visionClient = ImageAnnotatorClient.Create(); var text = await visionClient.DetectDocumentTextAsync(image); Console.WriteLine($"Text: {text.Text}"); Console.WriteLine(text.Pages.Select(p => p.Confidence.ToString())); LanguageServiceClient languageClient = LanguageServiceClient.Create(); Document document = Document.FromPlainText(text.Text); AnnotateTextResponse response = languageClient.AnnotateText(document, new Features { ExtractSyntax = true, ExtractEntities = true }); Console.WriteLine($"Detected language: {response.Language}"); // The Sentences and Tokens properties provide all kinds of information // about the parsed text. Console.WriteLine($"Number of sentences: {response.Sentences.Count}"); Console.WriteLine($"Number of tokens: {response.Tokens.Count}"); Console.WriteLine("Detected entities:"); foreach (Entity entity in response.Entities) { Console.WriteLine($" {entity.Name} ({(int)(entity.Salience * 100)}%)"); } }
public void TestDateMapping_LastTuesdayLowerCase() { var atr = new AnnotateTextResponse(); atr.Sentences.Add(new Sentence() { Text = new TextSpan() { Content = "Last tuesday I went to the shops" } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); //Look for last Wednesday var comparisonDate = DateTime.Today.AddDays(-1); while (comparisonDate.DayOfWeek != DayOfWeek.Tuesday) { comparisonDate = comparisonDate.AddDays(-1); } Assert.AreEqual(comparisonDate, claim.DateOfDamage); }
private static void CheckTime(AnnotateTextResponse response, Claim claim) { foreach (var sentence in response.Sentences) { CheckForLastDayOfWeek(sentence, claim); CheckForWellFormattedDate(sentence, claim); CheckForDateOfMonth(sentence, claim); } }
public ResultsLogic(String info) { Langpr = new LangProc(); response = Langpr.AnalyzeSyntaxFromText(info); var a = rntFact(); System.Console.WriteLine(); }
public Claim PopulateClaim(AnnotateTextResponse response) { var claim = PopulateClaim(response.Entities); PopulateFromTokens(response, claim); PopulateFromSentences(response, claim); return(claim); }
private void _gcNaturalLanguage_AnnotateTextSuccessEvent(AnnotateTextResponse annotationResult) { Debug.Log("Annotate Success!"); //Func<Entity, bool> personProperFilter = (x) => x.type != Enumerators.EntityType.PERSON && x.mentions.First().type != Enumerators.EntityMentionType.PROPER; Dictionary <string, double> termScores = scoreAllTerms(annotationResult); Dictionary <string, bool> termIsPersonMap = annotationResult.entities.ToDictionary(x => x.name, y => y.type == Enumerators.EntityType.PERSON); FindBestAssetForTerms(termScores, termIsPersonMap); }
private void PopulateFromTokens(AnnotateTextResponse response, Claim claim) { foreach (var token in response.Tokens.Where(token => token.PartOfSpeech.Tag == PartOfSpeech.Types.Tag.Verb)) { AnalyseVerbForDamage(token, claim); } foreach (var token in response.Tokens.Where(token => token.PartOfSpeech.Tag == PartOfSpeech.Types.Tag.Noun)) { AnalyseNounForTime(token, claim); } }
public void SetResponse(AnnotateTextResponse response) { Categories = response.Categories != null?JsonConvert.SerializeObject(response.Categories, Formatting.None) : null; DocumentSentiment = response.DocumentSentiment != null?JsonConvert.SerializeObject(response.DocumentSentiment, Formatting.None) : null; Entities = response.Entities != null?JsonConvert.SerializeObject(response.Entities, Formatting.None) : null; Sentences = response.Sentences != null?JsonConvert.SerializeObject(response.Sentences, Formatting.None) : null; Token = response.Tokens != null?JsonConvert.SerializeObject(response.Tokens, Formatting.None) : null; Response = response.Clone(); ResponseJson = response != null?JsonConvert.SerializeObject(Response, Formatting.None) : null; }
public void TestDateMapping_specificWithBackslashesAndSingleDigitDayAndMonthDoubleDigitYear() { var atr = new AnnotateTextResponse(); atr.Sentences.Add(new Sentence() { Text = new TextSpan() { Content = "On 6\\4\\16 I went to the shops" } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); Assert.AreEqual(new DateTime(2016, 4, 6), claim.DateOfDamage); }
public void TestDateMapping_specificWithSlashes() { var atr = new AnnotateTextResponse(); atr.Sentences.Add(new Sentence() { Text = new TextSpan() { Content = "On 11/04/2016 I went to the shops" } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); Assert.AreEqual(new DateTime(2016, 4, 11), claim.DateOfDamage); }
public void TestDamageMapping_StolenTokenPresent() { var atr = new AnnotateTextResponse(); atr.Tokens.Add(new Token() { Lemma = "steal", PartOfSpeech = new PartOfSpeech() { Tag = PartOfSpeech.Types.Tag.Verb } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.AreEqual(Claim.DamageType.Stolen, claim.TypeOfDamage); Assert.IsNull(claim.DateOfDamage); }
public void TestDateMapping_dayOfMonth() { for (var i = 1; i < 12; i++) { var atr = new AnnotateTextResponse(); atr.Sentences.Add(new Sentence() { Text = new TextSpan() { Content = "On the 6th of " + getMonth(i) + " I went to the shops" } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); Assert.AreEqual(new DateTime(DateTime.Now.Year, i, 6), claim.DateOfDamage); } }
public void TestEntityMapping_EntitiesOnly_NoDamage() { var atr = new AnnotateTextResponse(); atr.Entities.Add(new Entity() { Name = "iPhone", Type = Entity.Types.Type.ConsumerGood }); atr.Entities.Add(new Entity() { Name = "beach", Type = Entity.Types.Type.Location }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.AreEqual("iPhone", claim.DamagedItem); Assert.AreEqual("beach", claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); Assert.IsNull(claim.DateOfDamage); }
public void TestDateMapping_Yesterday() { var atr = new AnnotateTextResponse(); atr.Tokens.Add(new Token() { Text = new TextSpan() { Content = "Yesterday", }, PartOfSpeech = new PartOfSpeech() { Tag = PartOfSpeech.Types.Tag.Noun } }); var claim = new ClaimPopulator().PopulateClaim(atr); Assert.IsNull(claim.DamagedItem); Assert.IsNull(claim.DamageLocation); Assert.IsNull(claim.TypeOfDamage); Assert.AreEqual(DateTime.Today.AddDays(-1), claim.DateOfDamage); }
private Dictionary <string, double> scoreAllTerms(AnnotateTextResponse annotationResult) { Dictionary <string, double> termScores = new Dictionary <string, double>(); foreach (var item in annotationResult.entities) { string entityName = item.name.ToLower(); if (aliaser.ContainsKey(entityName)) { entityName = aliaser[entityName]; } string[] wordsInEntity = GetWords(entityName); if ((item.type == Enumerators.EntityType.PERSON || wordsInEntity.Count() > 1)) //grizzly bear, power lines, supreme court { var idf = getIdf(wordsInEntity); termScores[entityName] = getTermRelevancyScore(idf, item.salience); Debug.Log(String.Format("Word: {0} Term Salience: {1} Word IDF: {2} Score: {3}", item.name, item.salience, idf, termScores[entityName])); } if (item.type != Enumerators.EntityType.PERSON) //if not a person, try the terms individually as well { foreach (var word in wordsInEntity) { var idf = getIdf(word); termScores[word] = getTermRelevancyScore(idf, item.salience); Debug.Log(String.Format("Word: {0} Term Salience: {1} Word IDF: {2} Score: {3}", word, item.salience, idf, termScores[word])); } } } return(termScores); }