public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
public List<Constituent> getwordskfrom(View TOKENS, int startspan, int endspan, int k) { // This assumes that span is only representing a token if (k == 0) { return TOKENS.getConstituentsCoveringSpan(startspan, endspan); } else if (k < 0) { int kprevindex = startspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (kprevindex < 0) { kprevindex = 0; } return TOKENS.getConstituentsCoveringSpan(kprevindex, startspan); } else { int knextindex = endspan + k; // Checking the token index specified by kprevindex is // valid (i.e. non-negative) if (knextindex > TOKENS.getEndSpan()) { knextindex = TOKENS.getEndSpan(); } return TOKENS.getConstituentsCoveringSpan(endspan, knextindex); } }
/** * Get the constituents which cover the input constituent {@code c}. * * @param c A constituent, not necessarily of this text annotation. * @return A list of constituents, which cover the same tokens as the input */ public List<Constituent> getConstituentsCovering(Constituent c) { return this.getConstituentsCoveringSpan(c.getStartSpan(), c.getEndSpan()); }
/** * Get the constituents which cover the input constituent {@code c}. * * @param c A constituent, not necessarily of this text annotation. * @return A list of constituents, which cover the same tokens as the input */ public List<Constituent> getConstituentsCovering(Constituent c) { return this.getConstituentsCoveringSpan(c.getStartSpan(), c.getEndSpan()); }
public View getViewCoveringSpan(int start, int end, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringSpan(start, end)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); // logger.info(restriction); return restriction; }
public View getViewCoveringSpan(int start, int end, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringSpan(start, end)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); // logger.info(restriction); return restriction; }
public Constituent getLastConstituent() { if (span == null) return null; List<Constituent> c = getTextAnnotation().getView(ViewNames.TOKENS) .getConstituentsCoveringSpan(span.getFirst(), span.getSecond()); return c.get(c.size() - 1); }
public String[] getwindowkfrom(View TOKENS, int startspan, int endspan, int k) { String window[] = new String[2 * k + 1]; int startwin = startspan - k; int endwin = endspan + k; if (endwin > TOKENS.getEndSpan()) { endwin = TOKENS.getEndSpan(); } if (startwin < 0) { startwin = 0; } for (int i = startwin; i < endwin; i++) { window[i - startwin] = TOKENS.getConstituentsCoveringSpan(i, i + 1).get(0).getSurfaceForm(); } return window; }
public String[] getwindowkfrom(View TOKENS, int startspan, int endspan, int k) { String window[] = new String[2 * k + 1]; int startwin = startspan - k; int endwin = endspan + k; if (endwin > TOKENS.getEndSpan()) { endwin = TOKENS.getEndSpan(); } if (startwin < 0) { startwin = 0; } for (int i = startwin; i < endwin; i++) { window[i - startwin] = TOKENS.getConstituentsCoveringSpan(i, i + 1).get(0).getSurfaceForm(); } return window; }
public Constituent getFirstConstituent() { if (span == null) return null; return getTextAnnotation().getView(ViewNames.TOKENS) .getConstituentsCoveringSpan(span.getFirst(), span.getSecond()).get(0); }
@Override public Set<Feature> getFeatures(Constituent instance) throws EdisonException { Set<Feature> features = new LinkedHashSet<>(); View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS); List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan()); Collections.sort(list, TextAnnotationUtilities.constituentStartComparator); ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent,String>() { public String transform(Constituent input) { return input.getSurfaceForm(); } }; features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer)); features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer)); return features; } }
@Override public Set<Feature> getFeatures(Constituent instance) throws EdisonException { Set<Feature> features = new LinkedHashSet<>(); View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS); List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan()); list.sort(TextAnnotationUtilities.constituentStartComparator); ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent, String>() { public String transform(Constituent input) { return input.getSurfaceForm(); } }; features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer)); features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer)); return features; }
@Override public Set<Feature> getFeatures(Constituent instance) throws EdisonException { Set<Feature> features = new LinkedHashSet<>(); View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS); List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan()); list.sort(TextAnnotationUtilities.constituentStartComparator); ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent, String>() { public String transform(Constituent input) { return input.getSurfaceForm(); } }; features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer)); features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer)); return features; }
@Override public Set<Feature> getFeatures(Constituent instance) throws EdisonException { Set<Feature> features = new LinkedHashSet<Feature>(); View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS); List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan()); Collections.sort(list, TextAnnotationUtilities.constituentStartComparator); ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent, String>() { private static final long serialVersionUID = 1L; public String transform(Constituent input) { return input.getSurfaceForm(); } }; features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer)); features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer)); return features; } }
@Override public Set<Feature> getFeatures(Constituent instance) throws EdisonException { Set<Feature> features = new LinkedHashSet<Feature>(); View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS); List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan()); Collections.sort(list, TextAnnotationUtilities.constituentStartComparator); ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent, String>() { private static final long serialVersionUID = 1L; public String transform(Constituent input) { return input.getSurfaceForm(); } }; features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer)); features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer)); return features; } }
/** * Extracts an array of tokens from a uniform window of size k * * @param TOKENS The tokens {@link View} of the {@link TextAnnotation} object * @param startspan The span at the beginning of the {@link Constituent} object * @param endspan The span at the end of the {@link Constituent} object * @param k The number of tokens to the left and right of the current {@link Constituent} object * to get * @return The window of k tokens to the left and k tokens to the right of the current * {@link Constituent} object */ private String[] getWindowK(View TOKENS, int startspan, int endspan, int k) { String window[] = new String[2 * k + 1]; int startwin = startspan - k; int endwin = endspan + k; if (endwin > TOKENS.getEndSpan()) { endwin = TOKENS.getEndSpan(); } if (startwin < 0) { startwin = 0; } int index = 0; for (int i = startwin; i < endwin; i++) { window[index] = TOKENS.getConstituentsCoveringSpan(i, i + 1).get(0).getSurfaceForm(); index++; } return window; }