//line is a jsonstring of map of label to array of strings; ex: {"name":["Bush","Carter","Obama"]} /// <exception cref="System.Exception"/> public virtual string DoNewPhrases(string line) { System.Console.Out.WriteLine("adding new phrases"); ConstantsAndVariables constVars = new ConstantsAndVariables(props, humanLabelClasses.Keys, humanLabelClasses); IJsonReader jsonReader = Javax.Json.Json.CreateReader(new StringReader(line)); IJsonObject objarr = jsonReader.ReadObject(); foreach (KeyValuePair <string, IJsonValue> o in objarr) { string label = o.Key; ICollection <CandidatePhrase> seed = new HashSet <CandidatePhrase>(); IJsonArray arr = objarr.GetJsonArray(o.Key); for (int i = 0; i < arr.Count; i++) { string seedw = arr.GetString(i); System.Console.Out.WriteLine("adding " + seedw + " to seed "); seed.Add(CandidatePhrase.CreateOrGet(seedw)); } Sharpen.Collections.AddAll(seedWords[label], seed); constVars.AddSeedWords(label, seed); GetPatternsFromDataMultiClass.RunLabelSeedWords(Data.sents, humanLabelClasses[label], label, seed, constVars, false); } //model.labelWords(label, labelclass, Data.sents, seed); return("SUCCESS added new phrases"); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.TypeLoadException"/> internal virtual void SetUpProperties(string line, bool readFile, bool writeOutputToFile, string additionalSeedWordsFiles) { IJsonReader jsonReader = Javax.Json.Json.CreateReader(new StringReader(line)); IJsonObject objarr = jsonReader.ReadObject(); jsonReader.Close(); Properties props = new Properties(); foreach (string o in objarr.Keys) { if (o.Equals("seedWords")) { IJsonObject obj = objarr.GetJsonObject(o); foreach (string st in obj.Keys) { seedWords[st] = new HashSet <CandidatePhrase>(); IJsonArray arr = obj.GetJsonArray(st); for (int i = 0; i < arr.Count; i++) { string val = arr.GetString(i); seedWords[st].Add(CandidatePhrase.CreateOrGet(val)); System.Console.Out.WriteLine("adding " + val + " for label " + st); } } } else { props.SetProperty(o, objarr.GetString(o)); } } System.Console.Out.WriteLine("seedwords are " + seedWords); if (additionalSeedWordsFiles != null && !additionalSeedWordsFiles.IsEmpty()) { IDictionary <string, ICollection <CandidatePhrase> > additionalSeedWords = GetPatternsFromDataMultiClass.ReadSeedWords(additionalSeedWordsFiles); logger.Info("additional seed words are " + additionalSeedWords); foreach (string label in seedWords.Keys) { if (additionalSeedWords.Contains(label)) { Sharpen.Collections.AddAll(seedWords[label], additionalSeedWords[label]); } } } outputFile = null; if (readFile) { System.Console.Out.WriteLine("input value is " + objarr.GetString("input")); outputFile = props.GetProperty("input") + "_processed"; props.SetProperty("file", objarr.GetString("input")); if (writeOutputToFile && !props.Contains("columnOutputFile")) { props.SetProperty("columnOutputFile", outputFile); } } else { string systemdir = Runtime.GetProperty("java.io.tmpdir"); File tempFile = File.CreateTempFile("sents", ".tmp", new File(systemdir)); tempFile.DeleteOnExit(); IOUtils.WriteStringToFile(props.GetProperty("input"), tempFile.GetPath(), "utf8"); props.SetProperty("file", tempFile.GetAbsolutePath()); } SetProperties(props); this.props = props; int i_1 = 1; foreach (string label_1 in seedWords.Keys) { string ansclstr = "edu.stanford.nlp.patterns.PatternsAnnotations$PatternLabel" + i_1; Type mcCl = (Type)Sharpen.Runtime.GetType(ansclstr); machineAnswerClasses[label_1] = mcCl; string humanansclstr = "edu.stanford.nlp.patterns.PatternsAnnotations$PatternHumanLabel" + i_1; humanLabelClasses[label_1] = (Type)Sharpen.Runtime.GetType(humanansclstr); i_1++; } }