Search in sources :

Example 1 with NamedEntity

use of org.icij.datashare.text.NamedEntity in project datashare by ICIJ.

the class NamedEntityResourceTest method test_get_named_entity.

@Test
public void test_get_named_entity() {
    NamedEntity toBeReturned = create(PERSON, "mention", asList(123L), "docId", "root", CORENLP, FRENCH);
    doReturn(toBeReturned).when(indexer).get("index", "my_id", "root_parent");
    get("/api/index/namedEntities/my_id?routing=root_parent").should().respond(200).haveType("application/json");
}
Also used : NamedEntity(org.icij.datashare.text.NamedEntity) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 2 with NamedEntity

use of org.icij.datashare.text.NamedEntity in project datashare by ICIJ.

the class NamedEntityResourceTest method test_hide_named_entity_when_success.

@Test
public void test_hide_named_entity_when_success() throws IOException {
    NamedEntity toBeHidden = create(PERSON, "to_update", asList(123L), "docId", "root", CORENLP, FRENCH);
    assertThat(toBeHidden.isHidden()).isFalse();
    Indexer.Searcher searcher = mock(Indexer.Searcher.class);
    doReturn(Stream.of(toBeHidden)).when(searcher).execute();
    doReturn(searcher).when(searcher).thatMatchesFieldValue(any(), any());
    doReturn(searcher).when(indexer).search("index", NamedEntity.class);
    put("/api/index/namedEntities/hide/to_update").should().respond(200);
    verify(indexer).bulkUpdate("index", singletonList(toBeHidden));
}
Also used : NamedEntity(org.icij.datashare.text.NamedEntity) Indexer(org.icij.datashare.text.indexing.Indexer) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 3 with NamedEntity

use of org.icij.datashare.text.NamedEntity in project datashare by ICIJ.

the class EmailPipelineTest method test_acceptance.

@Test
public void test_acceptance() throws IOException {
    Path emailFile = Paths.get(getClass().getResource("/email.eml").getPath());
    String content = new String(Files.readAllBytes(emailFile));
    List<NamedEntity> annotations = pipeline.process(createDocument(content, "docId", Language.ENGLISH));
    assertThat(annotations).hasSize(3);
    assertThat(annotations.get(0).getOffsets()).containsExactly(14L, 48L, 168L, 332L, 1283L, 1482L, 1544L, 1582L);
}
Also used : Path(java.nio.file.Path) NamedEntity(org.icij.datashare.text.NamedEntity) Test(org.junit.Test)

Example 4 with NamedEntity

use of org.icij.datashare.text.NamedEntity in project datashare by ICIJ.

the class JooqRepositoryTest method test_create_named_entity_list.

@Test
public void test_create_named_entity_list() {
    List<NamedEntity> namedEntities = Arrays.asList(NamedEntity.create(PERSON, "mention 1", asList(123L), "doc_id", "root", CORENLP, GERMAN), NamedEntity.create(PERSON, "mention 2", asList(321L), "doc_id", "root", CORENLP, ENGLISH));
    repository.create(namedEntities);
    NamedEntity actualNe1 = repository.getNamedEntity(namedEntities.get(0).getId());
    assertThat(actualNe1).isEqualTo(namedEntities.get(0));
    assertThat(actualNe1.getCategory()).isEqualTo(PERSON);
    assertThat(actualNe1.getExtractor()).isEqualTo(CORENLP);
    assertThat(actualNe1.getExtractorLanguage()).isEqualTo(GERMAN);
    assertThat(repository.getNamedEntity(namedEntities.get(1).getId())).isEqualTo(namedEntities.get(1));
}
Also used : NamedEntity(org.icij.datashare.text.NamedEntity) Test(org.junit.Test)

Example 5 with NamedEntity

use of org.icij.datashare.text.NamedEntity in project datashare by ICIJ.

the class ElasticsearchIndexerTest method test_update_named_entity.

@Test
public void test_update_named_entity() throws IOException {
    Document parent = new org.icij.datashare.text.Document("id", project("prj"), Paths.get("doc.txt"), "content Madeline", Language.FRENCH, Charset.defaultCharset(), "text/plain", new HashMap<>(), DONE, new HashSet<>(), 123L);
    NamedEntity ne = create(PERSON, "Madeline", asList(8L), parent.getId(), "root", CORENLP, Language.ENGLISH);
    indexer.add(TEST_INDEX, parent);
    indexer.add(TEST_INDEX, ne);
    ne.hide();
    indexer.update(TEST_INDEX, ne);
    NamedEntity neFromES = indexer.get(TEST_INDEX, ne.getId(), parent.getId());
    assertThat(neFromES.isHidden()).isTrue();
}
Also used : NamedEntity(org.icij.datashare.text.NamedEntity) Document(org.icij.datashare.text.Document) Test(org.junit.Test)

Aggregations

NamedEntity (org.icij.datashare.text.NamedEntity)20 Test (org.junit.Test)16 Document (org.icij.datashare.text.Document)11 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 PropertiesProvider (org.icij.datashare.PropertiesProvider)2 Language (org.icij.datashare.text.Language)2 NamedEntitiesBuilder (org.icij.datashare.text.NamedEntitiesBuilder)2 AbstractPipeline (org.icij.datashare.text.nlp.AbstractPipeline)2 Annotations (org.icij.datashare.text.nlp.Annotations)2 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)2 Inject (com.google.inject.Inject)1 AbstractSequenceClassifier (edu.stanford.nlp.ie.AbstractSequenceClassifier)1 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 Triple (edu.stanford.nlp.util.Triple)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Path (java.nio.file.Path)1 java.util (java.util)1 Collection (java.util.Collection)1