Hi,
iam sending the contents of json file, for which i have coded a simpleextractor in c# ,to extract the entities “address” and “cas_number”.
Similarly pls anyone can help me with the code to extract the entities “hazard_statements” and “precautionary_statements”, in the contents of json file, would be great helpful. This simple extractor package we r using in UiPath validation station.
pls refer to the below json file contents:
{
“address”: [
{
“confidence”: “0.50”,
“entity”: “street1”
},
{
“confidence”: “0.41”,
“entity”: “street2”
}
],
“cas_number”: [
{
“confidence”: “0.60”,
“entity”: “89999”
}
],
“hazard_statements”: [
{
“code”: “J88”,
“desc”: “liquid”
}
],
“precautionary_statements”: [
{
“code”: “J89”,
“desc”: “inflammable”
},
{
“code”: “J90”,
“desc”: “extinguisher”
}
]
}
The simple extractor code for the above json file contents:
using Newtonsoft.Json;
using System.Activities;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using UiPath.DocumentProcessing.Contracts;
using UiPath.DocumentProcessing.Contracts.DataExtraction;
using UiPath.DocumentProcessing.Contracts.Dom;
using UiPath.DocumentProcessing.Contracts.Results;
using UiPath.DocumentProcessing.Contracts.Taxonomy;
namespace SampleActivities.Basic.DataExtraction
{
class EntityValue
{
public float Confidence { get; set; }
public string Entity { get; set; }
}
public class SimpleExtractor : ExtractorCodeActivity
{
public InArgument<string> InputText { get; set; }
public override Task<ExtractorDocumentTypeCapabilities[]> GetCapabilities()
{
return Task.FromResult(new ExtractorDocumentTypeCapabilities[0]);
}
protected override void Execute(CodeActivityContext context)
{
ExtractorDocumentType documentType = ExtractorDocumentType.Get(context);
Document document = DocumentObjectModel.Get(context);
string inputText = InputText.Get(context);
var parsedInput = JsonConvert.DeserializeObject<Dictionary<string, EntityValue[]>> (inputText);
ExtractorResult.Set(context, ComputeResult(documentType, document, parsedInput));
}
private ExtractorResult ComputeResult(ExtractorDocumentType documentType, Document document, Dictionary<string, EntityValue[]>parsedInput)
{
var extractorResult = new ExtractorResult();
var resultsDataPoints = new List<ResultsDataPoint>();
resultsDataPoints.Add(CreateAddressFieldDataPoint( document, parsedInput["address"]));
resultsDataPoints.Add(CreatecasNumberFieldDataPoint( document, parsedInput["cas_number"][0]));
extractorResult.DataPoints = resultsDataPoints.ToArray();
return extractorResult;
}
private static ResultsDataPoint CreateAddressFieldDataPoint(Document document, EntityValue[] address)
{
var booleanToken = new ResultsValueTokens(0, (float)document.Pages[0].Size.Width, (float)document.Pages[0].Size.Height, new[] {Box.CreateUnchecked(0, 0, 0, 0) });
var reference = new ResultsContentReference(0, 0, new[] { booleanToken });
var addressValues = new List<ResultsValue>();
foreach (var a in address)
{
addressValues.Add(new ResultsValue(a.Entity, reference, a.Confidence, 1f));
}
return new ResultsDataPoint(
"address","address",FieldType.Text,
addressValues.ToArray());
}
private static ResultsDataPoint CreatecasNumberFieldDataPoint( Document document, EntityValue cas_number)
{
var booleanToken = new ResultsValueTokens(0, (float)document.Pages[0].Size.Width, (float)document.Pages[0].Size.Height, new[] { Box.CreateUnchecked(0, 0, 0, 0) });
var reference = new ResultsContentReference(0, 0, new[] { booleanToken });
var secondcasNumberValue = new ResultsValue(cas_number.Entity, reference, cas_number.Confidence, 1f);
return new ResultsDataPoint(
"cas_number", "cas_number",FieldType.Number,
new[] { secondcasNumberValue });
}
}