public static String printConstituent( Constituent c ) { StringBuilder output = new StringBuilder(); output.append( "Constituent: Surface form: " ).append("'").append( c.getSurfaceForm() ).append( "'" ); // output.append( "\ns-exp: " ); // output.append( c_.toSExpression( true ) ); output.append( "\nLabel: " ).append( c.getLabel() ).append( "; view: " ).append( c.getViewName() ); output.append( "\n" ).append( "char offsets: " ).append( c.getStartCharOffset() ).append( ", " ); output.append( c.getEndCharOffset() ).append( "\ntoken offsets: " ).append( c.getStartSpan() ); output.append( ", " ).append( c.getEndSpan() ); output.append( "\nAttributes: "); for ( String attType : c.getAttributeKeys() ) { String val = c.getAttribute( attType ); output.append( "[").append( attType ).append( ", " ).append( val ).append( "], " ); } output.append( "\nLabel Scores: " ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) for ( Map.Entry<String, Double> e : labelsToScores.entrySet() ) output.append(e.getKey()).append(": ").append(e.getValue()).append(", "); else output.append(c.getLabel()).append(": ").append(c.getConstituentScore()); output.append( "\n" ); return output.toString(); }
public static String printConstituent( Constituent c ) { StringBuilder output = new StringBuilder(); output.append( "Constituent: Surface form: " ).append("'").append( c.getSurfaceForm() ).append( "'" ); // output.append( "\ns-exp: " ); // output.append( c_.toSExpression( true ) ); output.append( "\nLabel: " ).append( c.getLabel() ).append( "; view: " ).append( c.getViewName() ); output.append( "\n" ).append( "char offsets: " ).append( c.getStartCharOffset() ).append( ", " ); output.append( c.getEndCharOffset() ).append( "\ntoken offsets: " ).append( c.getStartSpan() ); output.append( ", " ).append( c.getEndSpan() ); output.append( "\nAttributes: "); for ( String attType : c.getAttributeKeys() ) { String val = c.getAttribute( attType ); output.append( "[").append( attType ).append( ", " ).append( val ).append( "], " ); } output.append( "\nLabel Scores: " ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) for ( Map.Entry<String, Double> e : labelsToScores.entrySet() ) output.append(e.getKey()).append(": ").append(e.getValue()).append(", "); else output.append(c.getLabel()).append(": ").append(c.getConstituentScore()); output.append( "\n" ); return output.toString(); }
.append(target.getTokenizedSurfaceForm()); if (target.getAttributeKeys().size() > 0) { sb.append("["); for (String key : Sorters.sortSet(target.getAttributeKeys())) { sb.append(key).append("=").append(target.getAttribute(key)).append(" ");
.append(target.getTokenizedSurfaceForm()); if (target.getAttributeKeys().size() > 0) { sb.append("["); for (String key : Sorters.sortSet(target.getAttributeKeys())) { sb.append(key).append("=").append(target.getAttribute(key)).append(" ");
new Constituent(ment.getLabel(), getCorefViewName(), ta, ment.getStartSpan(), ment.getEndSpan()); for (String att : ment.getAttributeKeys()) corefMent.addAttribute(att, ment.getAttribute(att)); corefMent.addAttribute(EntityIdAttribute, eId);
new Constituent(ment.getLabel(), getCorefViewName(), ta, ment.getStartSpan(), ment.getEndSpan()); for (String att : ment.getAttributeKeys()) corefMent.addAttribute(att, ment.getAttribute(att)); corefMent.addAttribute(EntityIdAttribute, eId);
/** * Helper function to create a head constituent from an extent constituent. */ public static Constituent getEntityHeadForConstituent(Constituent extentConstituent, TextAnnotation textAnnotation, String viewName) { int startCharOffset = Integer.parseInt(extentConstituent .getAttribute(ACEReader.EntityHeadStartCharOffset)); int endCharOffset = Integer.parseInt(extentConstituent.getAttribute(ACEReader.EntityHeadEndCharOffset)) - 1; int startToken = textAnnotation.getTokenIdFromCharacterOffset(startCharOffset); int endToken = textAnnotation.getTokenIdFromCharacterOffset(endCharOffset); if (startToken >= 0 && endToken >= 0 && !(endToken - startToken < 0)) { Constituent cons = new Constituent(extentConstituent.getLabel(), 1.0, viewName, textAnnotation, startToken, endToken + 1); for (String attributeKey : extentConstituent.getAttributeKeys()) { cons.addAttribute(attributeKey, extentConstituent.getAttribute(attributeKey)); } return cons; } return null; }
/** * * @param c The input full extent constituent * @param viewName The expected view name that you want the head constituent to have * @return A constituent that is only the head */ public static Constituent getHeadConstituent(Constituent c, String viewName){ if (c.getAttribute("EntityHeadStartSpan") == null || c.getAttribute("EntityHeadEndSpan") == null){ return null; } int cStart = Integer.parseInt(c.getAttribute("EntityHeadStartSpan")); int cEnd = Integer.parseInt(c.getAttribute("EntityHeadEndSpan")); Constituent ret = new Constituent(c.getLabel(), viewName, c.getTextAnnotation(), cStart, cEnd); for (String attributeKey : c.getAttributeKeys()) { ret.addAttribute(attributeKey, c.getAttribute(attributeKey)); } return ret; } }
/** * * @param c The input full extent constituent * @param viewName The expected view name that you want the head constituent to have * @return A constituent that is only the head */ public static Constituent getHeadConstituent(Constituent c, String viewName){ if (c.getAttribute("EntityHeadStartSpan") == null || c.getAttribute("EntityHeadEndSpan") == null){ return null; } int cStart = Integer.parseInt(c.getAttribute("EntityHeadStartSpan")); int cEnd = Integer.parseInt(c.getAttribute("EntityHeadEndSpan")); Constituent ret = new Constituent(c.getLabel(), viewName, c.getTextAnnotation(), cStart, cEnd); for (String attributeKey : c.getAttributeKeys()) { ret.addAttribute(attributeKey, c.getAttribute(attributeKey)); } return ret; } }
/** * Helper function to create a head constituent from an extent constituent. */ public static Constituent getEntityHeadForConstituent(Constituent extentConstituent, TextAnnotation textAnnotation, String viewName) { int startCharOffset = Integer.parseInt(extentConstituent .getAttribute(ACEReader.EntityHeadStartCharOffset)); int endCharOffset = Integer.parseInt(extentConstituent.getAttribute(ACEReader.EntityHeadEndCharOffset)) - 1; int startToken = textAnnotation.getTokenIdFromCharacterOffset(startCharOffset); int endToken = textAnnotation.getTokenIdFromCharacterOffset(endCharOffset); if (startToken >= 0 && endToken >= 0 && !(endToken - startToken < 0)) { Constituent cons = new Constituent(extentConstituent.getLabel(), 1.0, viewName, textAnnotation, startToken, endToken + 1); for (String attributeKey : extentConstituent.getAttributeKeys()) { cons.addAttribute(attributeKey, extentConstituent.getAttribute(attributeKey)); } return cons; } return null; }
public Constituent cloneForNewViewWithDestinationLabel(String newViewName, String Dlabel) { Constituent cloneC = new Constituent(this.labelsToScores, Dlabel, this.getConstituentScore(), newViewName, this.getTextAnnotation(), this.getStartSpan(), this.getEndSpan()); for (String k : this.getAttributeKeys()) { cloneC.addAttribute(k, this.getAttribute(k)); } return cloneC; }
public Constituent cloneForNewViewWithDestinationLabel(String newViewName, String Dlabel) { Constituent cloneC = new Constituent(this.labelsToScores, Dlabel, this.getConstituentScore(), newViewName, this.getTextAnnotation(), this.getStartSpan(), this.getEndSpan()); for (String k : this.getAttributeKeys()) { cloneC.addAttribute(k, this.getAttribute(k)); } return cloneC; }
private static void writeConstituent(Constituent constituent, ViewDataProto.Builder viewDataBuilder) { ConstituentProto.Builder constituentBuilder = ConstituentProto.newBuilder(); constituentBuilder.setLabel(constituent.getLabel()); constituentBuilder.setScore(constituent.getConstituentScore()); constituentBuilder.setStart(constituent.getStartSpan()); constituentBuilder.setEnd(constituent.getEndSpan()); if (constituent.getAttributeKeys().size() > 0) { for (String key : Sorters.sortSet(constituent.getAttributeKeys())) { constituentBuilder.putProperties(key, constituent.getAttribute(key)); } } Map<String, Double> labelsToScores = constituent.getLabelsToScores(); if (labelsToScores != null) { constituentBuilder.putAllLabelScoreMap(labelsToScores); } viewDataBuilder.addConstituents(constituentBuilder); }
private static void writeConstituent(Constituent constituent, ViewDataProto.Builder viewDataBuilder) { ConstituentProto.Builder constituentBuilder = ConstituentProto.newBuilder(); constituentBuilder.setLabel(constituent.getLabel()); constituentBuilder.setScore(constituent.getConstituentScore()); constituentBuilder.setStart(constituent.getStartSpan()); constituentBuilder.setEnd(constituent.getEndSpan()); if (constituent.getAttributeKeys().size() > 0) { for (String key : Sorters.sortSet(constituent.getAttributeKeys())) { constituentBuilder.putProperties(key, constituent.getAttribute(key)); } } Map<String, Double> labelsToScores = constituent.getLabelsToScores(); if (labelsToScores != null) { constituentBuilder.putAllLabelScoreMap(labelsToScores); } viewDataBuilder.addConstituents(constituentBuilder); }
public Constituent cloneForNewView(String newViewName) { Constituent cloneC = new Constituent(this.labelsToScores, this.getLabel(), this.getConstituentScore(), newViewName, this.getTextAnnotation(), this.getStartSpan(), this.getEndSpan()); for (String k : this.getAttributeKeys()) { cloneC.addAttribute(k, this.getAttribute(k)); } return cloneC; }
public Constituent cloneForNewView(String newViewName) { Constituent cloneC = new Constituent(this.labelsToScores, this.getLabel(), this.getConstituentScore(), newViewName, this.getTextAnnotation(), this.getStartSpan(), this.getEndSpan()); for (String k : this.getAttributeKeys()) { cloneC.addAttribute(k, this.getAttribute(k)); } return cloneC; }
first.getTextAnnotation(), first.getStartSpan(), second.getEndSpan()); for (String k : first.getAttributeKeys()) { combinedSent.addAttribute(k, first.getAttribute(k)); for (String k : second.getAttributeKeys()) { combinedSent.addAttribute(k, first.getAttribute(k));
startToken, endToken + 1); for (String attributeKey : extentConstituent.getAttributeKeys()) { cons.addAttribute(attributeKey, extentConstituent.getAttribute(attributeKey));
startToken, endToken + 1); for (String attributeKey : extentConstituent.getAttributeKeys()) { cons.addAttribute(attributeKey, extentConstituent.getAttribute(attributeKey));
for (Constituent co : ta.getView(ViewNames.TOKENS).getConstituents()){ Constituent c = co.cloneForNewView("RE_ANNOTATED"); for (String s : co.getAttributeKeys()){ c.addAttribute(s, co.getAttribute(s));