Java Code Examples for org.apache.uima.jcas.tcas.DocumentAnnotation#setDocumentReleasability()

The following examples show how to use org.apache.uima.jcas.tcas.DocumentAnnotation#setDocumentReleasability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureUtilsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringArray() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "ENG");
  rel.set(1, "WAL");
  rel.set(2, "SCO");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object[] o = FeatureUtils.featureToArray(f, da);
  assertEquals(3, o.length);
  assertTrue(o[0] instanceof String);
  assertEquals("ENG", (String) o[0]);
  assertTrue(o[1] instanceof String);
  assertEquals("WAL", (String) o[1]);
  assertTrue(o[2] instanceof String);
  assertEquals("SCO", (String) o[2]);
}
 
Example 2
Source File: FeatureUtilsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringArrayToObject() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "true");
  rel.set(1, "2");
  rel.set(2, "0.45");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object[] o = FeatureUtils.featureToArray(f, da);
  assertEquals(3, o.length);
  assertTrue(o[0] instanceof Boolean);
  assertTrue((Boolean) o[0]);
  assertTrue(o[1] instanceof Integer);
  assertEquals(new Integer(2), (Integer) o[1]);
  assertTrue(o[2] instanceof Double);
  assertEquals(new Double(0.45), (Double) o[2]);
}
 
Example 3
Source File: FeatureUtilsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringArrayToList() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "ENG");
  rel.set(1, "WAL");
  rel.set(2, "SCO");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  List<Object> o = FeatureUtils.featureToList(f, da);
  assertEquals(3, o.size());
  assertTrue(o.get(0) instanceof String);
  assertEquals("ENG", (String) o.get(0));
  assertTrue(o.get(1) instanceof String);
  assertEquals("WAL", (String) o.get(1));
  assertTrue(o.get(2) instanceof String);
  assertEquals("SCO", (String) o.get(2));
}
 
Example 4
Source File: ElasticsearchTestBase.java    From baleen with Apache License 2.0 6 votes vote down vote up
protected long createNoEntitiesDocument() {
  jCas.reset();
  jCas.setDocumentText("Hello World");
  jCas.setDocumentLanguage("en");

  long timestamp = System.currentTimeMillis();

  DocumentAnnotation da = getDocumentAnnotation(jCas);
  da.setTimestamp(timestamp);
  da.setSourceUri("test/no_entities");
  da.setDocType("test");
  da.setDocumentClassification("OFFICIAL");
  da.setDocumentCaveats(
      UimaTypesUtils.toArray(jCas, Arrays.asList(new String[] {"TEST_A", "TEST_B"})));
  da.setDocumentReleasability(
      UimaTypesUtils.toArray(jCas, Arrays.asList(new String[] {"ENG", "SCO", "WAL"})));

  return timestamp;
}
 
Example 5
Source File: JCasDeserialiser.java    From baleen with Apache License 2.0 5 votes vote down vote up
private void processDocumentAnnotation(
    final JCas jCas, final DocumentAnnotation da, final Map<String, Object> map) {
  da.setDocType((String) map.getOrDefault(JsonJCas.DA_DOCUMENT_TYPE, ""));
  da.setDocumentClassification((String) map.getOrDefault(JsonJCas.DA_CLASSIFICATION, ""));
  da.setLanguage((String) map.getOrDefault(JsonJCas.DA_LANGUAGE, ""));
  da.setSourceUri((String) map.getOrDefault(JsonJCas.DA_SOURCE_URI, ""));
  da.setTimestamp(((Number) map.getOrDefault(JsonJCas.DA_TIMESTAMP, 0)).longValue());

  da.setDocumentCaveats(
      UimaTypesUtils.toArray(
          jCas, (Collection<String>) map.getOrDefault(JsonJCas.DA_CAVEATS, null)));
  da.setDocumentReleasability(
      UimaTypesUtils.toArray(
          jCas, (Collection<String>) map.getOrDefault(JsonJCas.DA_RELEASABILITY, null)));
}
 
Example 6
Source File: FeatureUtilsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testNull() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "ENG");
  rel.set(1, "WAL");
  rel.set(2, "SCO");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object o = FeatureUtils.featureToObject(f, da);
  assertNull(o);
}
 
Example 7
Source File: FeatureUtilsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullArrayValue() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  da.setDocumentReleasability(null);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object[] o = FeatureUtils.featureToArray(f, da);
  assertEquals(0, o.length);
}
 
Example 8
Source File: MongoTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testNoEntities() throws Exception {
  jCas.setDocumentText(TEXT);
  jCas.setDocumentLanguage("en");

  long timestamp = System.currentTimeMillis();

  DocumentAnnotation da = getDocumentAnnotation(jCas);
  da.setTimestamp(timestamp);
  da.setSourceUri("test/no_entities");
  da.setDocType("test");
  da.setDocumentClassification("OFFICIAL");
  da.setDocumentCaveats(
      UimaTypesUtils.toArray(jCas, Arrays.asList(new String[] {"TEST_A", "TEST_B"})));
  da.setDocumentReleasability(
      UimaTypesUtils.toArray(jCas, Arrays.asList(new String[] {"ENG", "SCO", "WAL"})));

  ae.process(jCas);

  assertEquals(1, documents.count());
  Document result = documents.find().first();

  assertEquals(TEXT, result.get(Mongo.FIELD_CONTENT));
  assertEquals(
      "en", ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_LANGUAGE));

  assertEquals(
      new Date(timestamp),
      ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_TIMESTAMP));
  assertEquals(
      "test/no_entities",
      ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_SOURCE));

  assertEquals(
      "test", ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_TYPE));

  assertEquals(
      "OFFICIAL",
      ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_CLASSIFICATION));
  assertArrayEquals(
      new String[] {"TEST_A", "TEST_B"},
      ((Collection<String>)
              ((Document) result.get(Mongo.FIELD_DOCUMENT)).get(Mongo.FIELD_DOCUMENT_CAVEATS))
          .toArray());
  assertArrayEquals(
      new String[] {"ENG", "SCO", "WAL"},
      ((Collection<String>)
              ((Document) result.get(Mongo.FIELD_DOCUMENT))
                  .get(Mongo.FIELD_DOCUMENT_RELEASABILITY))
          .toArray());

  assertEquals(getDocumentAnnotation(jCas).getHash(), result.get(fields.getExternalId()));
}