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(); }
/** * create a new constituent with token offsets shifted by the specified amount * @param newTA TextAnnotation which will contain the new Constituent * @param c original Constituent to copy * @param offset the offset to shift token indexes of new Constituent. Can be negative. * @return the new Constituent */ public static Constituent copyConstituentWithNewTokenOffsets(TextAnnotation newTA, Constituent c, int offset) { int newStart = c.getStartSpan() + offset; int newEnd = c.getEndSpan() + offset; assert(newStart >= 0 && newStart <= newTA.size()); assert(newEnd >= 0 && newEnd <= newTA.size()); Constituent newCon = null; if (null != c.getLabelsToScores()) newCon = new Constituent(c.getLabelsToScores(), c.viewName, newTA, newStart, newEnd); else newCon = new Constituent(c.getLabel(), c.getConstituentScore(), c.viewName, newTA, newStart, newEnd); copyAttributesFromTo(c, newCon); return newCon; }
/** * create a new constituent with token offsets shifted by the specified amount * @param newTA TextAnnotation which will contain the new Constituent * @param c original Constituent to copy * @param offset the offset to shift token indexes of new Constituent. Can be negative. * @return the new Constituent */ public static Constituent copyConstituentWithNewTokenOffsets(TextAnnotation newTA, Constituent c, int offset) { int newStart = c.getStartSpan() + offset; int newEnd = c.getEndSpan() + offset; assert(newStart >= 0 && newStart <= newTA.size()); assert(newEnd >= 0 && newEnd <= newTA.size()); Constituent newCon = null; if (null != c.getLabelsToScores()) newCon = new Constituent(c.getLabelsToScores(), c.viewName, newTA, newStart, newEnd); else newCon = new Constituent(c.getLabel(), c.getConstituentScore(), c.viewName, newTA, newStart, newEnd); copyAttributesFromTo(c, newCon); return newCon; }
if (null == first.getLabelsToScores()) combinedSent = new Constituent(first.getLabel(), first.getConstituentScore(), ViewNames.SENTENCE, first.getTextAnnotation(), first.getStartSpan(), second.getEndSpan()); else combinedSent = new Constituent(first.getLabelsToScores(), ViewNames.SENTENCE, first.getTextAnnotation(), first.getStartSpan(), second.getEndSpan());
if (null == first.getLabelsToScores()) combinedSent = new Constituent(first.getLabel(), first.getConstituentScore(), ViewNames.SENTENCE, first.getTextAnnotation(), first.getStartSpan(), second.getEndSpan()); else combinedSent = new Constituent(first.getLabelsToScores(), ViewNames.SENTENCE, first.getTextAnnotation(), first.getStartSpan(), second.getEndSpan());
private static void writeConstituent(Constituent c, JsonObject cJ) { writeString("label", c.getLabel(), cJ); if (c.getConstituentScore() != 0) writeDouble("score", c.getConstituentScore(), cJ); writeInt("start", c.getStartSpan(), cJ); writeInt("end", c.getEndSpan(), cJ); writeAttributes(c, cJ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) writeLabelsToScores(labelsToScores, cJ); }
private static void writeConstituent(Constituent c, JsonObject cJ) { writeString("label", c.getLabel(), cJ); if (c.getConstituentScore() != 0) writeDouble("score", c.getConstituentScore(), cJ); writeInt("start", c.getStartSpan(), cJ); writeInt("end", c.getEndSpan(), cJ); writeAttributes(c, cJ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) writeLabelsToScores(labelsToScores, cJ); }
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); }