private Task BuildTree(AnalyzedDocument analyzedDoc) { return(Task.Run(() => { foreach (var term in analyzedDoc.Terms) { WriteToTrie(term.Key.Field, term.Key.Word.Value); } })); }
//[UnityTest, Order(20)] public IEnumerator TestAnalyzeDocument() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator( bearerToken: "{BEARER_TOKEN}" ); DiscoveryService cpdService = new DiscoveryService(versionDate, authenticator); cpdService.SetServiceUrl("{SERVICE_URL}"); cpdService.WithHeader("X-Watson-Test", "1"); Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to AnalyzeDocument..."); AnalyzedDocument analyzeDocumentResponse = null; using (FileStream fs = File.OpenRead(analyzeDocumentFile)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); cpdService.AnalyzeDocument( callback: (DetailedResponse <AnalyzedDocument> response, IBMError error) => { Log.Debug("DiscoveryServiceV2IntegrationTests", "AnalyzeDocument result: {0}", response.Response); analyzeDocumentResponse = response.Result; Assert.IsNull(error); Assert.IsNotNull(analyzeDocumentResponse); }, projectId: "{projectId}", collectionId: "{collectionId}", file: ms, filename: "exampleConfigurationData.json", fileContentType: "application/json" ); } } while (analyzeDocumentResponse == null) { yield return(null); } }
public void before_each_test_setup() { TargetContainer = new SummarizationInformationContainer(); TargetAnalyzedDocument = new AnalyzedDocument { ScoredSentences = TargetContainer.ScoredSentences, ScoredTextUnits = TargetContainer.ScoredTextUnits }; TargetContentSummarizer = Substitute.For <IContentSummarizer>(); TargetContentSummarizer.GetConcepts(Arg.Any <AnalyzedDocument>(), Arg.Any <ISummarizerArguments>()).Returns(new List <string>() { "concept" }); TargetContentSummarizer.GetSentences(Arg.Any <AnalyzedDocument>(), Arg.Any <ISummarizerArguments>()).Returns(new List <string>() { "sentence" }); TargetSummarizerArguments = Substitute.For <ISummarizerArguments>(); }
public override async Task <TaxContributionResponse> ReceiveTaxContributionHonor(TaxContributionInfo request, ServerCallContext context) { await this.InitializeWalletsAsync(); string endpoint = "https://receipt-tax-reader.cognitiveservices.azure.com"; AzureKeyCredential credential = new AzureKeyCredential(_azureFormRecognizerApiKey); DocumentAnalysisClient client = new DocumentAnalysisClient(new Uri(endpoint), credential); var receiptBytes = new byte[request.Receipt.Length]; request.Receipt.CopyTo(receiptBytes, 0); using var receiptStream = new MemoryStream(receiptBytes); AnalyzeDocumentOperation operation = await client.StartAnalyzeDocumentAsync("prebuilt-receipt", receiptStream); await operation.WaitForCompletionAsync(); AnalyzeResult result = operation.Value; for (int i = 0; i < result.Documents.Count; i++) { Console.WriteLine($"Document {i}:"); AnalyzedDocument document = result.Documents[i]; if (document.Fields.TryGetValue("TotalTax", out DocumentField? totalTaxField)) { if (totalTaxField.ValueType == DocumentFieldType.Double) { double totalTax = totalTaxField.AsDouble(); Console.WriteLine($"Total Tax: '{totalTax}', with confidence {totalTaxField.Confidence}"); var airDropTx = await Sdk.Transaction.CreateAsync(KeyPair.FromAccountId(request.AccountId), _airDropWallet.Server); // create trustline // Remember, the TRANSACTION source account is the user's account, thus any // OPERATION without a source account explicitly set will default to the // transaction's source account, which is the user's account. Thus, a // trustline is being made on the user's account. airDropTx.AddOperation( new ChangeTrustOperation.Builder(ChangeTrustAsset.Create(_playUSA)).Build(), null); airDropTx.AddOperation(new PaymentOperation.Builder( KeyPair.FromAccountId(request.AccountId), _playUSA, totalTax.ToString("N7")) .SetSourceAccount(_airDropWallet.KeyPairWithSecretSeed) .Build(), _airDropWallet.KeyPairWithSecretSeed); // create trustline // Remember, the TRANSACTION source account is the user's account, thus any // OPERATION without a source account explicitly set will default to the // transaction's source account, which is the user's account. Thus, a // trustline is being made on the user's account. airDropTx.AddOperation( new ChangeTrustOperation.Builder(ChangeTrustAsset.Create(_playMONEY)).Build(), null); airDropTx.AddOperation(new PaymentOperation.Builder( KeyPair.FromAccountId(request.AccountId), _playMONEY, (totalTax * UsaPricedInMoney).ToString("N7")) .SetSourceAccount(_airDropWallet.KeyPairWithSecretSeed) .Build(), _airDropWallet.KeyPairWithSecretSeed); var airDropTxXdr = airDropTx.GetXdr(); var signedAirDropTxXdr = stellar_dotnet_sdk.Transaction.FromEnvelopeXdr(airDropTxXdr); signedAirDropTxXdr.Sign(_airDropWallet.KeyPairWithSecretSeed, _airDropWallet.NetworkInfo); return(new TaxContributionResponse() { Success = new Success() { Success_ = true, Message = "Hello World!" }, SignedXdr = signedAirDropTxXdr.ToEnvelopeXdrBase64() }); } } } return(new TaxContributionResponse() { Success = new Success() { Success_ = false } }); }
public void throws_if_null_arguments_are_passed(AnalyzedDocument analyzedDocument, IContentSummarizer contentSummarizer, ISummarizerArguments summarizerArguments) { Assert.Throws<ArgumentNullException>( () => { Target.SummarizeAnalysedContent(analyzedDocument, contentSummarizer, summarizerArguments); }); }
public void before_each_test_setup() { TargetContainer = new SummarizationInformationContainer(); TargetAnalyzedDocument = new AnalyzedDocument { ScoredSentences = TargetContainer.ScoredSentences, ScoredTextUnits = TargetContainer.ScoredTextUnits }; TargetContentSummarizer = Substitute.For<IContentSummarizer>(); TargetContentSummarizer.GetConcepts(Arg.Any<AnalyzedDocument>(), Arg.Any<ISummarizerArguments>()) .Returns(new List<string> {"concept"}); TargetContentSummarizer.GetSentences(Arg.Any<AnalyzedDocument>(), Arg.Any<ISummarizerArguments>()) .Returns(new List<string> {"Sentence"}); TargetSummarizerArguments = Substitute.For<ISummarizerArguments>(); }
public void throws_if_null_arguments_are_passed(AnalyzedDocument analyzedDocument, IContentSummarizer contentSummarizer, ISummarizerArguments summarizerArguments) { Assert.That(() => Target.SummarizeAnalysedContent(analyzedDocument, contentSummarizer, summarizerArguments), Throws.TypeOf <ArgumentNullException>()); }
public async Task AnalyzeWithPrebuiltModelFromFileAsync() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; DocumentAnalysisClient client = new DocumentAnalysisClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); #region Snippet:FormRecognizerAnalyzeWithPrebuiltModelFromFileAsync #if SNIPPET string filePath = "<filePath>"; #else string filePath = DocumentAnalysisTestEnvironment.CreatePath("recommended_invoice.jpg"); #endif using var stream = new FileStream(filePath, FileMode.Open); AnalyzeDocumentOperation operation = await client.StartAnalyzeDocumentAsync("prebuilt-invoice", stream); await operation.WaitForCompletionAsync(); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the // prebuilt-invoice model, consult: // https://aka.ms/azsdk/formrecognizer/invoicefieldschema for (int i = 0; i < result.Documents.Count; i++) { Console.WriteLine($"Document {i}:"); AnalyzedDocument document = result.Documents[i]; if (document.Fields.TryGetValue("VendorName", out DocumentField vendorNameField)) { if (vendorNameField.ValueType == DocumentFieldType.String) { string vendorName = vendorNameField.AsString(); Console.WriteLine($"Vendor Name: '{vendorName}', with confidence {vendorNameField.Confidence}"); } } if (document.Fields.TryGetValue("CustomerName", out DocumentField customerNameField)) { if (customerNameField.ValueType == DocumentFieldType.String) { string customerName = customerNameField.AsString(); Console.WriteLine($"Customer Name: '{customerName}', with confidence {customerNameField.Confidence}"); } } if (document.Fields.TryGetValue("Items", out DocumentField itemsField)) { if (itemsField.ValueType == DocumentFieldType.List) { foreach (DocumentField itemField in itemsField.AsList()) { Console.WriteLine("Item:"); if (itemField.ValueType == DocumentFieldType.Dictionary) { IReadOnlyDictionary <string, DocumentField> itemFields = itemField.AsDictionary(); if (itemFields.TryGetValue("Description", out DocumentField itemDescriptionField)) { if (itemDescriptionField.ValueType == DocumentFieldType.String) { string itemDescription = itemDescriptionField.AsString(); Console.WriteLine($" Description: '{itemDescription}', with confidence {itemDescriptionField.Confidence}"); } } if (itemFields.TryGetValue("Amount", out DocumentField itemAmountField)) { if (itemAmountField.ValueType == DocumentFieldType.Currency) { CurrencyValue itemAmount = itemAmountField.AsCurrency(); Console.WriteLine($" Amount: '{itemAmount.Symbol}{itemAmount.Amount}', with confidence {itemAmountField.Confidence}"); } } } } } } if (document.Fields.TryGetValue("SubTotal", out DocumentField subTotalField)) { if (subTotalField.ValueType == DocumentFieldType.Currency) { CurrencyValue subTotal = subTotalField.AsCurrency(); Console.WriteLine($"Sub Total: '{subTotal.Symbol}{subTotal.Amount}', with confidence {subTotalField.Confidence}"); } } if (document.Fields.TryGetValue("TotalTax", out DocumentField totalTaxField)) { if (totalTaxField.ValueType == DocumentFieldType.Currency) { CurrencyValue totalTax = totalTaxField.AsCurrency(); Console.WriteLine($"Total Tax: '{totalTax.Symbol}{totalTax.Amount}', with confidence {totalTaxField.Confidence}"); } } if (document.Fields.TryGetValue("InvoiceTotal", out DocumentField invoiceTotalField)) { if (invoiceTotalField.ValueType == DocumentFieldType.Currency) { CurrencyValue invoiceTotal = invoiceTotalField.AsCurrency(); Console.WriteLine($"Invoice Total: '{invoiceTotal.Symbol}{invoiceTotal.Amount}', with confidence {invoiceTotalField.Confidence}"); } } } #endregion }
public void throws_if_null_arguments_are_passed(AnalyzedDocument analyzedDocument, IContentSummarizer contentSummarizer, ISummarizerArguments summarizerArguments) { Target.SummarizeAnalysedContent(analyzedDocument, contentSummarizer, summarizerArguments); }