public string Extract([FromBody] TextExtractLearnInput input) { var programLearned = string.Empty; var programType = string.Empty; var output = new TextExtractLearnAndRunOutput(); var results = "No results"; try { var textProcessor = new TextExtractProcessor(); if (input.type == TextExtractType.Single.ToString()) { programLearned = textProcessor.LearnSingle(input.examples); programType = TextExtractType.Single.ToString(); } else if (input.type == TextExtractType.Sequence.ToString()) { programLearned = textProcessor.LearnSequence(input.examples); programType = TextExtractType.Sequence.ToString(); } else { if (TextExtractProcessor.IsSequence(input.examples)) { programLearned = textProcessor.LearnSequence(input.examples); programType = TextExtractType.Sequence.ToString(); } else { programLearned = textProcessor.LearnSingle(input.examples); programType = TextExtractType.Single.ToString(); } } var serializedProg = programLearned; if (!string.IsNullOrEmpty(programLearned)) { var inp = new TextExtractRunInput(); inp.program = programLearned; inp.text = input.examples[0].text; inp.type = TextExtractType.Sequence.ToString(); results = Run(inp); } } catch (Exception e) { return(JsonConvert.SerializeObject(results )); } return(JsonConvert.SerializeObject( results )); }
public string Learn([FromBody] TextExtractLearnInput input) { var programLearned = string.Empty; var programType = string.Empty; try { var textProcessor = new TextExtractProcessor(); if (input.type == TextExtractType.Single.ToString()) { programLearned = textProcessor.LearnSingle(input.examples); programType = TextExtractType.Single.ToString(); } else if (input.type == TextExtractType.Sequence.ToString()) { programLearned = textProcessor.LearnSequence(input.examples); programType = TextExtractType.Sequence.ToString(); } else { if (TextExtractProcessor.IsSequence(input.examples)) { programLearned = textProcessor.LearnSequence(input.examples); programType = TextExtractType.Sequence.ToString(); } else { programLearned = textProcessor.LearnSingle(input.examples); programType = TextExtractType.Single.ToString(); } } var output = new TextExtractLearnOutput() { program = programLearned, type = programType }; return(JsonConvert.SerializeObject(output.program)); } catch (Exception e) { return("Nothing learned"); } }