當前位置: 首頁>>代碼示例>>Java>>正文


Java CAS類代碼示例

本文整理匯總了Java中org.apache.uima.cas.CAS的典型用法代碼示例。如果您正苦於以下問題:Java CAS類的具體用法?Java CAS怎麽用?Java CAS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CAS類屬於org.apache.uima.cas包,在下文中一共展示了CAS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: defaultFeatureMapper

import org.apache.uima.cas.CAS; //導入依賴的package包/類
/**
 * {@code FeatureCopier} used for features which are references to {@code FeatureStructure}s.
 *
 * @param fromFeature the {@link Feature}
 * @param fromFs the {@link FeatureStructure} to copy from
 * @param toFs the {@link FeatureStructure} to copy to
 */
private void defaultFeatureMapper(Feature fromFeature, FeatureStructure fromFs,
    FeatureStructure toFs) {
  TypeSystem typeSystem = fromFs.getCAS().getTypeSystem();
  if (typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), fromFeature.getRange())) {
    STRING_COPIER.copy(fromFeature, fromFs, toFs);
  } else {
    FeatureStructure fromFeatureValue = fromFs.getFeatureValue(fromFeature);
    if (fromFeatureValue != null) {
      FeatureStructure toFeatureValue = fsEncounteredCallback.apply(fromFeatureValue);
      Feature toFeature = toFs.getType().getFeatureByBaseName(fromFeature.getShortName());
      toFs.setFeatureValue(toFeature, toFeatureValue);
    }
  }
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:22,代碼來源:FeatureCopiers.java

示例2: getNext

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void getNext(CAS aCAS)
        throws IOException, CollectionException
{
    // nextTarEntry cannot be null here!
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    int size = IOUtils.copy(tarArchiveInputStream, buffer);

    String entryName = nextTarEntry.getName();
    getLogger().debug("Loaded " + size + " bytes from " + entryName);

    // and move forward
    fastForwardToNextValidEntry();

    // and now create JCas
    InputStream inputStream = new ByteArrayInputStream(buffer.toByteArray());
    try {
        XmiCasDeserializer.deserialize(inputStream, aCAS, lenient);
    }
    catch (SAXException e) {
        throw new IOException(e);
    }
}
 
開發者ID:UKPLab,項目名稱:argument-reasoning-comprehension-task,代碼行數:24,代碼來源:CompressedXmiReader.java

示例3: process

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void process(CAS cas)
        throws AnalysisEngineProcessException
{
    String text = cas.getDocumentText();

    // NOTE: Twokenize provides a API call that performs a normalization first - this would
    // require a mapping to the text how it is present in the CAS object. Due to HTML escaping
    // that would become really messy, we use the call which does not perform any normalization
    List<String> tokenize = Twokenize.tokenize(text);
    int offset = 0;
    for (String t : tokenize) {
        int start = text.indexOf(t, offset);
        int end = start + t.length();
        createTokenAnnotation(cas, start, end);
        offset = end;
    }

}
 
開發者ID:UKPLab,項目名稱:argument-reasoning-comprehension-task,代碼行數:20,代碼來源:ArkTweetTokenizerFixed.java

示例4: getNext

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void getNext(CAS aCAS)
    throws IOException, CollectionException
{
    super.getNext(aCAS);

    JCas jcas;
    try {
        jcas = aCAS.getJCas();
        JCasId id = new JCasId(jcas);
        id.setId(jcasId++);
        id.addToIndexes();
    }
    catch (CASException e) {
        throw new CollectionException();
    }

    TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
    outcome.setOutcome(getTextClassificationOutcome(jcas));
    outcome.addToIndexes();

    if (!suppress) {
        new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
    }
}
 
開發者ID:Horsmann,項目名稱:FlexTag,代碼行數:26,代碼來源:TestReaderSingleLabel.java

示例5: process

import org.apache.uima.cas.CAS; //導入依賴的package包/類
/**
 * Use the given analysis engine and process the given text
 * You must release the return cas yourself
 * @param text the text to rpocess
 * @return the processed cas
 */
public CAS process(String text) {
    CAS cas = retrieve();

    cas.setDocumentText(text);
    try {
        analysisEngine.process(cas);
    } catch (AnalysisEngineProcessException e) {
        if (text != null && !text.isEmpty())
            return process(text);
        throw new RuntimeException(e);
    }

    return cas;


}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:23,代碼來源:UimaResource.java

示例6: FsCopiers

import org.apache.uima.cas.CAS; //導入依賴的package包/類
/**
 * Convenience constructor which only needs the callback for encountered feature structures.
 *
 * @param featureStructureEncounteredCallback callback for encountered feature structures
 */
FsCopiers(UnaryOperator<FeatureStructure> featureStructureEncounteredCallback) {
  this.featureCopiers = new FeatureCopiers(featureStructureEncounteredCallback);
  this.featureStructureEncounteredCallback = featureStructureEncounteredCallback;

  fsCopiers = new HashMap<>();
  fsCopiers.put(CAS.TYPE_NAME_BOOLEAN_ARRAY, copyArray(BooleanArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_BYTE_ARRAY, copyArray(ByteArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_DOUBLE_ARRAY, copyArray(DoubleArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FLOAT_ARRAY, copyArray(FloatArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FS_ARRAY, this::copyFsArray);
  fsCopiers.put(CAS.TYPE_NAME_LONG_ARRAY, copyArray(LongArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_INTEGER_ARRAY, copyArray(IntArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_SHORT_ARRAY, copyArray(ShortArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_STRING_ARRAY, copyArray(StringArrayFS.class));
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:21,代碼來源:FsCopiers.java

示例7: buildForNameMap

import org.apache.uima.cas.CAS; //導入依賴的package包/類
private static Map<String, ValueType> buildForNameMap() {
    Map<String, ValueType> forNameMap = new HashMap<>();
    forNameMap.put(CAS.TYPE_NAME_BOOLEAN, BOOLEAN);
    forNameMap.put(CAS.TYPE_NAME_BYTE, BYTE);
    forNameMap.put(CAS.TYPE_NAME_SHORT, SHORT);
    forNameMap.put(CAS.TYPE_NAME_INTEGER, INTEGER);
    forNameMap.put(CAS.TYPE_NAME_LONG, LONG);
    forNameMap.put(CAS.TYPE_NAME_FLOAT, FLOAT);
    forNameMap.put(CAS.TYPE_NAME_DOUBLE, DOUBLE);
    forNameMap.put(CAS.TYPE_NAME_STRING, STRING);
    forNameMap.put(CAS.TYPE_NAME_BOOLEAN_ARRAY, BOOLEAN_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_BYTE_ARRAY, BYTE_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_SHORT_ARRAY, SHORT_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_INTEGER_ARRAY, INTEGER_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_LONG_ARRAY, LONG_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_FLOAT_ARRAY, FLOAT_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_DOUBLE_ARRAY, DOUBLE_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_STRING_ARRAY, STRING_ARRAY);
    forNameMap.put(CAS.TYPE_NAME_FLOAT_LIST, FLOAT_LIST);
    forNameMap.put(CAS.TYPE_NAME_INTEGER_LIST, INTEGER_LIST);
    forNameMap.put(CAS.TYPE_NAME_STRING_LIST, STRING_LIST);

    return Collections.unmodifiableMap(forNameMap);
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:25,代碼來源:ValueTypes.java

示例8: SofaData

import org.apache.uima.cas.CAS; //導入依賴的package包/類
SofaData(String casIdentifier,
         CAS cas,
         Predicate<String> typeFilter) {
    identifierForFsRef = new ConcurrentHashMap<>();
    childToParentMap = new ConcurrentHashMap<>();
    documentLocationMap = new ConcurrentHashMap<>();

    this.casIdentifier = casIdentifier;
    this.cas = cas;
    this.typeFilter = typeFilter;

    SofaFS sofa = cas.getSofa();
    String text;
    if (sofa == null || (text = sofa.getLocalStringData()) == null) {
        text = "";
    }
    documentText = TRAILING_WHITESPACE.matcher(text).replaceFirst("");

    documentIdentifier = HASH_FUNCTION.hashString(documentText, Charsets.UTF_8);

    casViewIdentifier = Strings.base64UUID();

    fsRefQueue = new LinkedBlockingQueue<>();
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:25,代碼來源:SofaData.java

示例9: CasProcessor

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Inject
CasProcessor(CasViewProcessorFactory casViewProcessorFactory,
             @Assisted CasProcessorSettings casProcessorSettings,
             @Assisted CAS cas) {
    this.casViewProcessorFactory = casViewProcessorFactory;
    this.casProcessorSettings = casProcessorSettings;
    typeSystemInfo = casProcessorSettings.getTypeSystemInfo();
    casProcessingDelegate = casProcessorSettings.getCasProcessingDelegate();
    this.cas = cas;
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:11,代碼來源:CasProcessor.java

示例10: testEnumeratedStringCopier

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Test
public void testEnumeratedStringCopier() throws Exception {
  new Expectations() {{
    fromFeature.getRange();
    result = fromType;
    fromType.getName();
    result = "SomeOtherTypeName";
    fromFs.getStringValue(fromFeature);
    result = "aString";
    typeSystem.getType(CAS.TYPE_NAME_STRING);
    result = stringType;
    typeSystem.subsumes(stringType, fromType);
    result = true;
  }};

  featureCopiers.copyFeature(fromFeature, fromFs, toFs);

  new Verifications() {{
    toFs.setStringValue(toFeature, "aString");
    callback.apply(withInstanceOf(FeatureStructure.class));
    times = 0;
  }};
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:24,代碼來源:FeatureCopiersTest.java

示例11: CasViewProcessor

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Inject
CasViewProcessor(Client client,
                 FeatureStructureProcessorFactory featureStructureProcessorFactory,
                 @Assisted CasProcessorSettings casProcessorSettings,
                 @Assisted SofaData sofaData) throws InterruptedException {
    this.client = client;
    this.featureStructureProcessorFactory = featureStructureProcessorFactory;

    this.casProcessorSettings = casProcessorSettings;
    typeSystemInfo = casProcessorSettings.getTypeSystemInfo();
    casProcessingDelegate = casProcessorSettings.getCasProcessingDelegate();


    this.sofaData = sofaData;
    this.fsRefQueue = sofaData.getFsRefQueue();

    CAS cas = sofaData.getCas();

    lowLevelCAS = cas.getLowLevelCAS();
    Type topType = cas.getTypeSystem().getTopType();
    FSIterator<FeatureStructure> allIndexedFS = cas.getIndexRepository().getAllIndexedFS(topType);
    while (allIndexedFS.hasNext()) {
        sofaData.getIdentifierForFs(allIndexedFS.next());
    }
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:26,代碼來源:CasViewProcessor.java

示例12: adaptFile

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void adaptFile(CAS cas, Path path) throws CollectionException, IOException {
  LOGGER.debug("Reading text into a CAS view.");
  CAS targetView = cas.createView(viewName);

  byte[] bytes = Files.readAllBytes(path);
  String documentText = new String(bytes,
      Objects.requireNonNull(encoding,
          "Encoding must not be null"));
  targetView.setDocumentText(documentText);

  String fileName = path.getFileName().toString();
  int period = fileName.lastIndexOf('.');
  if (period == -1) {
    period = fileName.length();
  }
  String documentId = fileName.substring(0, period);
  UimaAdapters.createDocument(cas, null, documentId);
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:20,代碼來源:PlainTextInputFileAdapter.java

示例13: adaptFile

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void adaptFile(CAS cas, Path path) throws CollectionException {
  LOGGER.info("Deserializing an input stream into a cas");
  try (InputStream inputStream = Files.newInputStream(path)) {
    XmiCasDeserializer.deserialize(inputStream, cas,
        !(failOnUnknownType == null || failOnUnknownType));
  } catch (SAXException | IOException e) {
    LOGGER.error("Failed on document: {}", path);
    throw new CollectionException(e);
  }

  if (addDocumentId != null && addDocumentId) {
    CAS metadata = cas.getView("metadata");

    Type idType = metadata.getTypeSystem()
        .getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
    Feature idFeat = idType.getFeatureByBaseName("documentId");

    FeatureStructure fs = metadata.createFS(idType);
    fs.setStringValue(idFeat, path.getFileName().toString());
    metadata.addFsToIndexes(fs);
  }
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:24,代碼來源:XmiInputFileAdapter.java

示例14: setArrayValue

import org.apache.uima.cas.CAS; //導入依賴的package包/類
public static void setArrayValue(CommonArrayFS array, int index, Object value) {
	String name = array.getType().getName();
	if (CAS.TYPE_NAME_BOOLEAN_ARRAY.equals(name)) 
		((BooleanArrayFS)array).set(index, (Boolean) value);
	else if (CAS.TYPE_NAME_BYTE_ARRAY.equals(name)) 
		((ByteArrayFS)array).set(index, (Byte) value);
	else if (CAS.TYPE_NAME_DOUBLE_ARRAY.equals(name)) 
		((DoubleArrayFS)array).set(index, (Double) value);
	else if (CAS.TYPE_NAME_FLOAT_ARRAY.equals(name)) 
		((FloatArrayFS)array).set(index, (Float) value);
	else if (CAS.TYPE_NAME_INTEGER_ARRAY.equals(name)) 
		((IntArrayFS)array).set(index, (Integer) value);
	else if (CAS.TYPE_NAME_LONG_ARRAY.equals(name)) 
		((LongArrayFS)array).set(index, (Long) value);
	else if (CAS.TYPE_NAME_SHORT_ARRAY.equals(name)) 
		((ShortArrayFS)array).set(index, (Short) value);
	else if (CAS.TYPE_NAME_STRING_ARRAY.equals(name)) 
		((StringArrayFS)array).set(index, (String) value);
	else  
		((ArrayFS)array).set(index, (FeatureStructure) value);
}
 
開發者ID:argo-nactem,項目名稱:nactem-type-mapper,代碼行數:22,代碼來源:UimaUtils.java

示例15: process

import org.apache.uima.cas.CAS; //導入依賴的package包/類
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
  Type documentIdType = aCAS.getTypeSystem()
      .getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
  Feature docIdFeat = documentIdType.getFeatureByBaseName("documentId");

  String documentId = aCAS.getIndexRepository()
      .getAllIndexedFS(documentIdType)
      .get()
      .getStringValue(docIdFeat);

  if (documentId == null) {
    documentId = UUID.randomUUID().toString();
  }

  GridFSInputFile file = gridFS.createFile(documentId + ".xmi");

  try (OutputStream outputStream = file.getOutputStream()) {
    XmiCasSerializer.serialize(aCAS, outputStream);
  } catch (IOException | SAXException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:24,代碼來源:MongoDbXmiWriter.java


注:本文中的org.apache.uima.cas.CAS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。