private bool CompatibleLabel(string label, ExtractionObject rel) { if (rel == null) { return(true); } if (validator != null) { return(validator.ValidLabel(label, rel)); } return(true); }
/// <summary> /// Method used to extract objects from a string list which is based on the /// output of an AutoCAD List command /// </summary> /// <remarks> /// Note that the properties that are extracted from the object are as follows: /// From Polylines and lines lengths are extracted, /// From Hatches areas are extracted, /// From blocks polylines, lines and hatches are all extracted and placed into groups /// for the exporting to a CSV file. /// </remarks> /// <param name="textList"> /// The AutoCAD List command text broken up into /// a string list /// </param> /// <param name="obj">The objects that you would like to extract</param> /// <returns>a list of lengths for lines or a list of areas for hatches</returns> public static List <double> ExtractObjects(IEnumerable <string> textList, ExtractionObject obj) { var returnList = new List <double>(); // Switch on the object type that is being extracted. switch (obj) { case ExtractionObject.PolylinesAndLines: { // Go through each line, parse the text from a line that // matches a regex and then parse that line. When the line is parsed // then place the property into a list foreach (var thisLine in textList) { if (PolylineRegex.IsMatch(thisLine)) { returnList.Add(double.Parse(ParsePolylineText(thisLine))); } else if (LineRegex.IsMatch(thisLine)) { returnList.Add(double.Parse(ParseLineText(thisLine))); } } } break; case ExtractionObject.Hatches: // Parses the line and converts it to a double, then adds it to // the return list returnList.AddRange( from thisLine in textList where HatchRegex.IsMatch(thisLine) select double.Parse(ParseHatchText(thisLine))); break; default: throw new ArgumentOutOfRangeException(nameof(obj), obj, null); } return(returnList); }
private static Element MakeProbabilitiesElement(ExtractionObject @object, string curNS) { Element probs = new Element("probabilities", curNS); if (@object.GetTypeProbabilities() != null) { IList <Pair <string, double> > sorted = Counters.ToDescendingMagnitudeSortedListWithCounts(@object.GetTypeProbabilities()); foreach (Pair <string, double> lv in sorted) { Element prob = new Element("probability", curNS); Element label = new Element("label", curNS); label.AppendChild(lv.first); Element value = new Element("value", curNS); value.AppendChild(lv.second.ToString()); prob.AppendChild(label); prob.AppendChild(value); probs.AppendChild(prob); } } return(probs); }
private RelationMention ConvertAceRelationMention(AceRelationMention aceRelationMention, string docId, ICoreMap sentence, IDictionary <string, EntityMention> entityMap) { IList <AceRelationMentionArgument> args = Arrays.AsList(aceRelationMention.GetArgs()); IList <ExtractionObject> convertedArgs = new List <ExtractionObject>(); IList <string> argNames = new List <string>(); // the arguments are already stored in semantic order. Make sure we preserve the same ordering! int left = int.MaxValue; int right = int.MinValue; foreach (AceRelationMentionArgument arg in args) { ExtractionObject o = entityMap[arg.GetContent().GetId()]; if (o == null) { logger.Severe("READER ERROR: Failed to find relation argument with id " + arg.GetContent().GetId()); logger.Severe("This happens because a few relation mentions illegally span multiple sentences. Will ignore this mention."); return(null); } convertedArgs.Add(o); argNames.Add(arg.GetRole()); if (o.GetExtentTokenStart() < left) { left = o.GetExtentTokenStart(); } if (o.GetExtentTokenEnd() > right) { right = o.GetExtentTokenEnd(); } } if (argNames.Count != 2 || !Sharpen.Runtime.EqualsIgnoreCase(argNames[0], "arg-1") || !Sharpen.Runtime.EqualsIgnoreCase(argNames[1], "arg-2")) { logger.Severe("READER ERROR: Invalid succession of arguments in relation mention: " + argNames); logger.Severe("ACE relations must have two arguments. Will ignore this mention."); return(null); } RelationMention relation = new RelationMention(aceRelationMention.GetId(), sentence, new Span(left, right), aceRelationMention.GetParent().GetType(), aceRelationMention.GetParent().GetSubtype(), convertedArgs, null); return(relation); }
private EventMention ConvertAceEventMention(AceEventMention aceEventMention, string docId, ICoreMap sentence, IDictionary <string, EntityMention> entityMap, int tokenOffset) { ICollection <string> roleSet = aceEventMention.GetRoles(); IList <string> roles = new List <string>(); foreach (string role in roleSet) { roles.Add(role); } IList <ExtractionObject> convertedArgs = new List <ExtractionObject>(); int left = int.MaxValue; int right = int.MinValue; foreach (string role_1 in roles) { AceEntityMention arg = aceEventMention.GetArg(role_1); ExtractionObject o = entityMap[arg.GetId()]; if (o == null) { logger.Severe("READER ERROR: Failed to find event argument with id " + arg.GetId()); logger.Severe("This happens because a few event mentions illegally span multiple sentences. Will ignore this mention."); return(null); } convertedArgs.Add(o); if (o.GetExtentTokenStart() < left) { left = o.GetExtentTokenStart(); } if (o.GetExtentTokenEnd() > right) { right = o.GetExtentTokenEnd(); } } AceCharSeq anchor = aceEventMention.GetAnchor(); ExtractionObject anchorObject = new ExtractionObject(aceEventMention.GetId() + "-anchor", sentence, new Span(anchor.GetTokenStart() - tokenOffset, anchor.GetTokenEnd() + 1 - tokenOffset), "ANCHOR", null); EventMention em = new EventMention(aceEventMention.GetId(), sentence, new Span(left, right), aceEventMention.GetParent().GetType(), aceEventMention.GetParent().GetSubtype(), anchorObject, convertedArgs, roles); return(em); }
protected internal virtual string ClassOf(IDatum <string, string> datum, ExtractionObject rel) { ICounter <string> probs = classifier.ProbabilityOf(datum); IList <Pair <string, double> > sortedProbs = Counters.ToDescendingMagnitudeSortedListWithCounts(probs); double nrProb = probs.GetCount(RelationMention.Unrelated); foreach (Pair <string, double> choice in sortedProbs) { if (choice.first.Equals(RelationMention.Unrelated)) { return(choice.first); } if (nrProb >= choice.second) { return(RelationMention.Unrelated); } // no prediction, all probs have the same value if (CompatibleLabel(choice.first, rel)) { return(choice.first); } } return(RelationMention.Unrelated); }
public virtual bool ValidLabel(string label, ExtractionObject @object) { return(true); }