Refine search
public static Set<FeatureStructure> collectIndexed(CAS aCas) { LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> fses = new TreeSet<>(Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fses::add); return fses; }
@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); } }
/** * @param cas * The CAS the index lives in. * @param indexName * The name of the index to create the helper object for. * @param type * The subtype to restrict the index to, <code>null</code> to use the index base type. */ public IndexInfo(CAS cas, String indexName, Type type) { this.indexName = indexName; this.cas = cas; if (type == null) fsIndex = cas.getIndexRepository().getIndex(indexName); else fsIndex = cas.getIndexRepository().getIndex(indexName, type); }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas, String artifactID ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.createView("metadata"); metadataCas.setDocumentText(""); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); this.artifactID = artifactID; FeatureStructure documentIdFs = metadataCas.createFS(idType); documentIdFs.setStringValue(idFeat, artifactID); metadataCas.addFsToIndexes(documentIdFs); metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
public void populateCas(Sentence sentence, CAS tcas) throws AnalysisEngineProcessException, CASRuntimeException { typeSystemInit(tcas.getTypeSystem()); AnnotationFS sentenceAnn = tcas.createAnnotation(mSentenceType, sentence.getStart(), sentence.getEnd()); tcas.getIndexRepository().addFS(sentenceAnn); token.getFeatures()); tcas.getIndexRepository().addFS(tokenAnnotationArr[i]); i++; tcas.getIndexRepository().addFS(chunkAnn); tcas.getIndexRepository().addFS(syntChunkAnn);
Type type = cas.getTypeSystem().getType("ArtifactID"); Feature documentId = type.getFeatureByBaseName("artifactID"); String fileName = cas.getView("metadata") .getIndexRepository() .getAllIndexedFS(type) .next() .getStringValue(documentId) + ".xmi";
try { int currPos = 0; offsets = new int[((int) (aCAS.getDocumentText().length() * 1.7)) + 100]; Collection<Token> tokens = JCasUtil.select(aCAS.getJCas(), Token.class); matchType = aCAS.getDocumentAnnotation().getType(); aCAS.getIndexRepository().addFS(annotsToAdd.get(x));
String text = tcas.getDocumentText(); Document document = new DocumentImpl(text); AnnotationFS sentenceAnn = tcas.createAnnotation(mSentenceType, sentence.getStart(), sentence.getEnd()); tcas.getIndexRepository().addFS(sentenceAnn); token.getFeatures()); tcas.getIndexRepository().addFS(tokenAnnotationArr[i]); i++; tcas.getIndexRepository().addFS(chunkAnn); tcas.getIndexRepository().addFS(syntChunkAnn);
/** * Create a {@link Collection} of the given type of feature structures. This collection is backed * by the CAS, either via an {@link CAS#getAnnotationIndex(Type)} or * {@link FSIndexRepository#getAllIndexedFS(Type)}. * * @param cas * the CAS to select from. * @param type * the type of feature structures to select. All sub-types are returned as well. * @return a {@link Collection} of the given type of feature structures backed live by the CAS. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<FeatureStructure> create(CAS cas, Type type) { // If the type is an annotation type, we can use the annotation index, which directly // provides us with its size. If not, we have to use getAllIndexedFS() which we have to // scan from beginning to end in order to determine its size. TypeSystem ts = cas.getTypeSystem(); if (ts.subsumes(cas.getAnnotationType(), type)) { return (Collection) create(cas.getAnnotationIndex(type)); } else { return create(cas.getIndexRepository().getAllIndexedFS(type)); } }
private void addChunkAnnotation(CAS tcas, AnnotationFS[] tokenAnnotations, String tag, int start, int end) { AnnotationFS chunk = tcas.createAnnotation(mChunkType, tokenAnnotations[start].getBegin(), tokenAnnotations[end - 1].getEnd()); chunk.setStringValue(mChunkFeature, tag); tcas.getIndexRepository().addFS(chunk); }
TypeSystem typeSystem = cas.getTypeSystem(); tokenFilter.initTypes(typeSystem, false); tokenType = typeSystem.getType(tokenTypeName); FSIterator tokenIter = cas.getIndexRepository().getAllIndexedFS(tokenType); logger.logWarning ("Dictionary tokenization of: '" + cas.getDocumentText() + "' produced no tokens of type: '" + tokenType.getName () + "'");
public void process(CAS aCAS) throws AnalysisEngineProcessException { // get handle to CAS view containing XML document CAS xmlCas = aCAS.getView("xmlDocument"); InputStream xmlStream = xmlCas.getSofa().getSofaDataStream(); // parse with detag handler DetagHandler handler = new DetagHandler(); try { SAXParser parser = parserFactory.newSAXParser(); parser.parse(xmlStream, handler); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } // create the plain text view and set its document text CAS plainTextView = aCAS.createView("plainTextDocument"); plainTextView.setDocumentText(handler.getDetaggedText()); plainTextView.setDocumentLanguage(aCAS.getView("_InitialView").getDocumentLanguage()); // Index the SourceDocumentInformation object, if there is one, in the new sofa. // This is needed by the SemanticSearchCasIndexer Iterator iter = xmlCas.getAnnotationIndex(sourceDocInfoType).iterator(); if (iter.hasNext()) { FeatureStructure sourceDocInfoFs = (FeatureStructure) iter.next(); plainTextView.getIndexRepository().addFS(sourceDocInfoFs); } }
CAS targetView = getOrCreateView(mDestCas, aSrcCasView.getViewName()); String sofaMime = aSrcCasView.getSofa().getSofaMime(); if (aSrcCasView.getDocumentText() != null) { targetView.setSofaDataString(aSrcCasView.getDocumentText(), sofaMime); Iterator<FSIndex<FeatureStructure>> indexes = aSrcCasView.getIndexRepository().getIndexes(); while (indexes.hasNext()) { FSIndex<FeatureStructure> index = indexes.next();
cas.removeFsFromIndexes(annotation); nameAnnotations[i] = cas.createAnnotation(nameType, startIndex, endIndex); cas.getIndexRepository().addFS(nameAnnotations[i]);
protected AnnotationFS createAnnotation(CAS cas, int offset, Parse parse) { Parse[] parseChildren = parse.getChildren(); AnnotationFS[] parseChildAnnotations = new AnnotationFS[parseChildren.length]; // do this for all children for (int i = 0; i < parseChildren.length; i++) { parseChildAnnotations[i] = createAnnotation(cas, offset, parseChildren[i]); } AnnotationFS parseAnnotation = cas.createAnnotation(mParseType, offset + parse.getSpan().getStart(), offset + parse.getSpan().getEnd()); parseAnnotation.setStringValue(mTypeFeature, parse.getType()); if (probabilityFeature != null) { parseAnnotation.setDoubleValue(probabilityFeature, parse.getProb()); } ArrayFS childrenArray = cas.createArrayFS(parseChildAnnotations.length); childrenArray.copyFromArray(parseChildAnnotations, 0, 0, parseChildAnnotations.length); parseAnnotation.setFeatureValue(childrenFeature, childrenArray); cas.getIndexRepository().addFS(parseAnnotation); return parseAnnotation; }
@Override public void process(CAS cas) throws AnalysisEngineProcessException { FSIterator<FeatureStructure> typeFSIter = cas.getIndexRepository().getAllIndexedFS(idType); cas.removeFsFromIndexes(idFs); XmiCasSerializer serializer = new XmiCasSerializer(cas.getTypeSystem()); try { serializer.serialize(cas, xmiBytes);
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.getView("metadata"); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); FSIndexRepository indexRepository = metadataCas.getIndexRepository(); artifactID = indexRepository.getIndex("artifactID", idType).iterator().get() .getStringValue(idFeat); metadataIndex = indexRepository.getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
public static void copyFeatureStructuresOfType(String typeName, CAS sourceView, CAS destinationView) { FeatureStructureCopyingQueue featureStructureCopyingQueue = new FeatureStructureCopyingQueue( sourceView, destinationView); FSIterator<FeatureStructure> iterator = sourceView.getIndexRepository() .getAllIndexedFS(sourceView.getTypeSystem().getType(typeName)); while (iterator.hasNext()) { FeatureStructure featureStructure = iterator.get(); featureStructureCopyingQueue.enqueue(featureStructure); } featureStructureCopyingQueue.run(); }
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; }
FSIndexRepository ir = this.cas.getIndexRepository(); Iterator<String> it = ir.getLabels(); while (it.hasNext()) { 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));