public void ExtractEntityLinkingBatchConvenience() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); var documents = new List <string> { "Microsoft was founded by Bill Gates and Paul Allen.", "Text Analytics is one of the Azure Cognitive Services.", "Pike place market is my favorite Seattle attraction.", }; #region Snippet:TextAnalyticsSample6RecognizeLinkedEntitiesConvenience RecognizeLinkedEntitiesResultCollection results = client.RecognizeLinkedEntitiesBatch(documents); #endregion Debug.WriteLine($"Linked entities for each document are:\n"); int i = 0; foreach (RecognizeLinkedEntitiesResult result in results) { Debug.Write($"For document: \"{documents[i++]}\", "); Debug.WriteLine($"extracted {result.Entities.Count()} linked entit{(result.Entities.Count() > 1 ? "ies" : "y")}:"); foreach (LinkedEntity linkedEntity in result.Entities) { Debug.WriteLine($" Name: \"{linkedEntity.Name}\", Language: {linkedEntity.Language}, Data Source: {linkedEntity.DataSource}, Url: {linkedEntity.Url.ToString()}, Entity Id in Data Source: \"{linkedEntity.DataSourceEntityId}\""); foreach (LinkedEntityMatch match in linkedEntity.Matches) { Debug.WriteLine($" Match Text: \"{match.Text}\", Offset (in UTF-16 code units): {match.Offset}, Length (in UTF-16 code units): {match.Length}"); Debug.WriteLine($" Confidence score: {match.ConfidenceScore}"); } } Debug.WriteLine(""); } }
public void ExtractEntityLinkingBatchConvenience() { string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT"); string apiKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_API_KEY"); // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new TextAnalyticsApiKeyCredential(apiKey)); var inputs = new List <string> { "Microsoft was founded by Bill Gates and Paul Allen.", "Text Analytics is one of the Azure Cognitive Services.", "Pike place market is my favorite Seattle attraction.", }; #region Snippet:TextAnalyticsSample6RecognizeLinkedEntitiesConvenience RecognizeLinkedEntitiesResultCollection results = client.RecognizeLinkedEntitiesBatch(inputs); #endregion Debug.WriteLine($"Linked entities for each input are:\n"); int i = 0; foreach (RecognizeLinkedEntitiesResult result in results) { Debug.Write($"For input: \"{inputs[i++]}\", "); Debug.WriteLine($"extracted {result.Entities.Count()} linked entit{(result.Entities.Count() > 1 ? "ies" : "y")}:"); foreach (LinkedEntity linkedEntity in result.Entities) { Debug.WriteLine($" Name: \"{linkedEntity.Name}\", Id: \"{linkedEntity.Id}\", Language: {linkedEntity.Language}, Data Source: {linkedEntity.DataSource}, Url: {linkedEntity.Url.ToString()}"); foreach (LinkedEntityMatch match in linkedEntity.Matches) { Debug.WriteLine($" Match Text: \"{match.Text}\", Score: {match.Score:0.00}, Offset: {match.Offset}, Length: {match.Length}."); } } Debug.WriteLine(""); } }
public void ExtractEntityLinkingBatch() { string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT"); string apiKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_API_KEY"); // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new TextAnalyticsApiKeyCredential(apiKey)); #region Snippet:TextAnalyticsSample6RecognizeLinkedEntitiesBatch var inputs = new List <TextDocumentInput> { new TextDocumentInput("1", "Microsoft was founded by Bill Gates and Paul Allen.") { Language = "en", }, new TextDocumentInput("2", "Text Analytics is one of the Azure Cognitive Services.") { Language = "en", }, new TextDocumentInput("3", "Pike place market is my favorite Seattle attraction.") { Language = "en", } }; RecognizeLinkedEntitiesResultCollection results = client.RecognizeLinkedEntitiesBatch(inputs, new TextAnalyticsRequestOptions { IncludeStatistics = true }); #endregion int i = 0; Debug.WriteLine($"Results of Azure Text Analytics \"Entity Linking\", version: \"{results.ModelVersion}\""); Debug.WriteLine(""); foreach (RecognizeLinkedEntitiesResult result in results) { TextDocumentInput document = inputs[i++]; Debug.WriteLine($"On document (Id={document.Id}, Language=\"{document.Language}\", Text=\"{document.Text}\"):"); if (result.HasError) { Debug.WriteLine($" Document error code: {result.Error.Code}."); Debug.WriteLine($" Message: {result.Error.Message}."); } else { Debug.WriteLine($" Extracted the following {result.Entities.Count()} linked entities:"); foreach (LinkedEntity linkedEntity in result.Entities) { Debug.WriteLine($" Name: \"{linkedEntity.Name}\", Language: {linkedEntity.Language}, Data Source: {linkedEntity.DataSource}, Url: {linkedEntity.Url.ToString()}, Entity Id in Data Source: \"{linkedEntity.DataSourceEntityId}\""); foreach (LinkedEntityMatch match in linkedEntity.Matches) { Debug.WriteLine($" Match Text: \"{match.Text}\", Score: {match.Score:0.00}, Offset: {match.Offset}, Length: {match.Length}."); } } Debug.WriteLine($" Document statistics:"); Debug.WriteLine($" Character count: {result.Statistics.CharacterCount}"); Debug.WriteLine($" Transaction count: {result.Statistics.TransactionCount}"); Debug.WriteLine(""); } } Debug.WriteLine($"Batch operation statistics:"); Debug.WriteLine($" Document count: {results.Statistics.DocumentCount}"); Debug.WriteLine($" Valid document count: {results.Statistics.ValidDocumentCount}"); Debug.WriteLine($" Invalid document count: {results.Statistics.InvalidDocumentCount}"); Debug.WriteLine($" Transaction count: {results.Statistics.TransactionCount}"); Debug.WriteLine(""); }
public void ExtractEntityLinkingBatch() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions()); #region Snippet:TextAnalyticsSample6RecognizeLinkedEntitiesBatch string documentA = @"Microsoft was founded by Bill Gates with some friends he met at Harvard. One of his friends, Steve Ballmer, eventually became CEO after Bill Gates as well.Steve Ballmer eventually stepped down as CEO of Microsoft, and was succeeded by Satya Nadella. Microsoft originally moved its headquarters to Bellevue, Washington in Januaray 1979, but is now headquartered in Redmond"; string documentB = @"El CEO de Microsoft es Satya Nadella, quien asumió esta posición en Febrero de 2014. Él empezó como Ingeniero de Software en el año 1992."; string documentC = @"Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman chief executive officer, president and chief software architect while also being the largest individual shareholder until May 2014."; var documents = new List <TextDocumentInput> { new TextDocumentInput("1", documentA) { Language = "en", }, new TextDocumentInput("2", documentB) { Language = "es", }, new TextDocumentInput("3", documentC) { Language = "en", }, new TextDocumentInput("4", string.Empty) }; var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; Response <RecognizeLinkedEntitiesResultCollection> response = client.RecognizeLinkedEntitiesBatch(documents, options); RecognizeLinkedEntitiesResultCollection entitiesPerDocuments = response.Value; int i = 0; Console.WriteLine($"Results of \"Entity Linking\", version: \"{entitiesPerDocuments.ModelVersion}\""); Console.WriteLine(""); foreach (RecognizeLinkedEntitiesResult entitiesInDocument in entitiesPerDocuments) { TextDocumentInput document = documents[i++]; Console.WriteLine($"On document (Id={document.Id}, Language=\"{document.Language}\"):"); if (entitiesInDocument.HasError) { Console.WriteLine(" Error!"); Console.WriteLine($" Document error code: {entitiesInDocument.Error.ErrorCode}."); Console.WriteLine($" Message: {entitiesInDocument.Error.Message}"); } else { Console.WriteLine($"Recognized {entitiesInDocument.Entities.Count} entities:"); foreach (LinkedEntity linkedEntity in entitiesInDocument.Entities) { Console.WriteLine($" Name: {linkedEntity.Name}"); Console.WriteLine($" Language: {linkedEntity.Language}"); Console.WriteLine($" Data Source: {linkedEntity.DataSource}"); Console.WriteLine($" URL: {linkedEntity.Url}"); Console.WriteLine($" Entity Id in Data Source: {linkedEntity.DataSourceEntityId}"); foreach (LinkedEntityMatch match in linkedEntity.Matches) { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); } Console.WriteLine($" Document statistics:"); Console.WriteLine($" Character count: {entitiesInDocument.Statistics.CharacterCount}"); Console.WriteLine($" Transaction count: {entitiesInDocument.Statistics.TransactionCount}"); } Console.WriteLine(""); } Console.WriteLine($"Batch operation statistics:"); Console.WriteLine($" Document count: {entitiesPerDocuments.Statistics.DocumentCount}"); Console.WriteLine($" Valid document count: {entitiesPerDocuments.Statistics.ValidDocumentCount}"); Console.WriteLine($" Invalid document count: {entitiesPerDocuments.Statistics.InvalidDocumentCount}"); Console.WriteLine($" Transaction count: {entitiesPerDocuments.Statistics.TransactionCount}"); Console.WriteLine(""); #endregion }
public void ExtractEntityLinkingBatchConvenience() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions()); #region Snippet:TextAnalyticsSample6RecognizeLinkedEntitiesConvenience string documentA = @"Microsoft was founded by Bill Gates with some friends he met at Harvard. One of his friends, Steve Ballmer, eventually became CEO after Bill Gates as well.Steve Ballmer eventually stepped down as CEO of Microsoft, and was succeeded by Satya Nadella. Microsoft originally moved its headquarters to Bellevue, Washington in Januaray 1979, but is now headquartered in Redmond"; string documentB = @"Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman chief executive officer, president and chief software architect while also being the largest individual shareholder until May 2014."; string documentC = string.Empty; var documents = new List <string> { documentA, documentB, documentC }; Response <RecognizeLinkedEntitiesResultCollection> response = client.RecognizeLinkedEntitiesBatch(documents); RecognizeLinkedEntitiesResultCollection entitiesInDocuments = response.Value; int i = 0; Console.WriteLine($"Results of Azure Text Analytics \"Entity Linking\", version: \"{entitiesInDocuments.ModelVersion}\""); Console.WriteLine(""); foreach (RecognizeLinkedEntitiesResult entitiesInDocument in entitiesInDocuments) { Console.WriteLine($"On document with Text: \"{documents[i++]}\""); Console.WriteLine(""); if (entitiesInDocument.HasError) { Console.WriteLine(" Error!"); Console.WriteLine($" Document error code: {entitiesInDocument.Error.ErrorCode}."); Console.WriteLine($" Message: {entitiesInDocument.Error.Message}"); } else { Console.WriteLine($"Recognized {entitiesInDocument.Entities.Count} entities:"); foreach (LinkedEntity linkedEntity in entitiesInDocument.Entities) { Console.WriteLine($" Name: {linkedEntity.Name}"); Console.WriteLine($" Language: {linkedEntity.Language}"); Console.WriteLine($" Data Source: {linkedEntity.DataSource}"); Console.WriteLine($" URL: {linkedEntity.Url}"); Console.WriteLine($" Entity Id in Data Source: {linkedEntity.DataSourceEntityId}"); foreach (LinkedEntityMatch match in linkedEntity.Matches) { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); } } Console.WriteLine(""); } #endregion }