allRemoveAnnotations.iterator(), containingConstraint);
@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
@Override public boolean contains(FeatureStructure fs) { return this.index.contains(fs); }
final int size = index.size(); this.rootString = "<html><font color=green>" + indexName + "</font> - <font color=blue>" + index.getType().getName() + "</font> [" + size + "]</html>"; this.root = new FSNode(this, FSNode.DISPLAY_NODE, null, 0, null); this.fss = new ArrayList<FSNode>(); FSIterator<TOP> it = index.iterator(); int count = 0; for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
@Override public void actionPerformed(ActionEvent event) { String title = this.main.getIndexLabel() + " - " + this.main.getIndex().getType().getName(); MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title); f.addWindowListener(new CloseAnnotationViewHandler(this.main)); FSIterator it = this.main.getIndex().iterator(); final String text = this.main.getCas().getDocumentText(); System.out.println("Creating extents."); AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(), this.main .getStyleMap()); System.out.println("Initializing text frame."); f.init(text, extents, this.main.getDimension(MainFrame.annotViewSizePref)); System.out.println("Done."); }
@Override public FeatureStructure find(FeatureStructure fs) { return this.index.find(fs); }
@Override public Type getType() { return this.index.getType(); }
@Override public int size() { return metadataIndex.size(); } };
String label = it.next(); FSIndex index1 = ir.getIndex(label); IndexTreeNode nodeObj = new IndexTreeNode(label, index1.getType(), index1.size()); DefaultMutableTreeNode node = new DefaultMutableTreeNode(nodeObj); root.add(node); node.add(createTypeTree(index1.getType(), this.cas.getTypeSystem(), label, ir));
@Nullable @Override public String get(Object key) { if (!(key instanceof String)) { return null; } FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, (String) key); FeatureStructure fs = metadataIndex.find(check); return fs.getStringValue(valueFeature); }
public Object getType() { return fsIndex.getType(); }
protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }
public static <T extends TOP> T getFeatureStructureAtIndex(JCas jCas, Class<T> cls, int index) { try { int type = (Integer) cls.getField("type").get(null); FSIndex fsIndex = jCas.getAnnotationIndex(type); if (index < 0) throw new IllegalArgumentException("index less than zero: index=" + index); if (index >= fsIndex.size()) throw new IllegalArgumentException("index greater than or equal to fsIndex.size(): index=" + index); FSIterator iterator = fsIndex.iterator(); Object obj = null; for (int i = 0; i <= index; i++) { obj = iterator.next(); } return cls.cast(obj); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), iae); } catch (NoSuchFieldException nsfe) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), nsfe); } }
public String toString() { if (isIndex) { return "" + fsIndex.size() + " entries"; } return "Expand to show"; }
@Nullable @Override public String put(String key, String value) { FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, key); FeatureStructure fs = metadataIndex.find(check); String existing = null; if (fs != null) { existing = fs.getStringValue(valueFeature); metadataCas.removeFsFromIndexes(fs); } else { fs = check; } fs.setStringValue(valueFeature, value); metadataCas.addFsToIndexes(fs); return existing; }
public Object getSubTypes() { FSIndexRepository ir = cas.getIndexRepository(); Type type = fsIndex.getType(); List<Type> subtypes = cas.getTypeSystem().getProperlySubsumedTypes(type); DebugNameValuePair[] r = new DebugNameValuePair[subtypes.size()]; int i = 0; Iterator<Type> it = subtypes.iterator(); while (it.hasNext()) { Type stype = it.next(); r[i++] = new DebugNameValuePair("Type: " + stype.getName(), new UnexpandedFeatureStructures(ir.getIndex(indexName, stype))); } return r; }
@Override public boolean containsKey(Object key) { if (!(key instanceof String)) { return false; } FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, (String) key); return metadataIndex.contains(check); } }
@Override public FSIterator<T> iterator() { return (FSIterator<T>) this.index.iterator(); }