Search in sources :

Example 11 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class SampleExtraction method writeSampleIndex.

public static void writeSampleIndex() throws Exception {
    // parse the original file
    File sourceFileFolder = new File(promedFilesDirectory);
    ArrayList<Tuple> fileTuples = new ArrayList<>();
    for (File htmlFile : sourceFileFolder.listFiles()) {
        StringBuilder sb = new StringBuilder();
        Scanner scanner = new Scanner(htmlFile);
        while (scanner.hasNext()) {
            sb.append(scanner.nextLine());
        }
        scanner.close();
        Tuple tuple = parsePromedHTML(htmlFile.getName(), sb.toString());
        if (tuple != null) {
            fileTuples.add(tuple);
        }
    }
    // write tuples into the table
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(PROMED_SAMPLE_TABLE);
    relationManager.createTable(PROMED_SAMPLE_TABLE, promedIndexDirectory, PromedSchema.PROMED_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(PROMED_SAMPLE_TABLE);
    dataWriter.open();
    for (Tuple tuple : fileTuples) {
        dataWriter.insertTuple(tuple);
    }
    dataWriter.close();
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) File(java.io.File) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 12 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class KeywordTestHelper method writeTestTables.

public static void writeTestTables() throws TextDBException {
    RelationManager relationManager = RelationManager.getRelationManager();
    // create the people table and write tuples
    relationManager.createTable(PEOPLE_TABLE, "../index/test_tables/" + PEOPLE_TABLE, TestConstants.SCHEMA_PEOPLE, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter peopleDataWriter = relationManager.getTableDataWriter(PEOPLE_TABLE);
    peopleDataWriter.open();
    for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
        peopleDataWriter.insertTuple(tuple);
    }
    peopleDataWriter.close();
    // create the medline table and write tuples
    relationManager.createTable(MEDLINE_TABLE, "../index/test_tables/" + MEDLINE_TABLE, keywordTestConstants.SCHEMA_MEDLINE, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter medDataWriter = relationManager.getTableDataWriter(MEDLINE_TABLE);
    medDataWriter.open();
    for (Tuple tuple : keywordTestConstants.getSampleMedlineRecord()) {
        medDataWriter.insertTuple(tuple);
    }
    medDataWriter.close();
    // create the people table and write tuples in Chinese
    relationManager.createTable(CHINESE_TABLE, "../index/test_tables/" + CHINESE_TABLE, TestConstantsChinese.SCHEMA_PEOPLE, LuceneAnalyzerConstants.chineseAnalyzerString());
    DataWriter chineseDataWriter = relationManager.getTableDataWriter(CHINESE_TABLE);
    chineseDataWriter.open();
    for (Tuple tuple : TestConstantsChinese.getSamplePeopleTuples()) {
        chineseDataWriter.insertTuple(tuple);
    }
    chineseDataWriter.close();
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 13 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTestWithLimit.

public void getNextTupleTestWithLimit() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = Arrays.asList(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL, 3, 0);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    // ExpectedResults is the array containing all the matches.
    // Since the order of returning records in returnedResults is not deterministic, we use containsAll
    // to ensure that the records in returnedResults are included in the ExpectedResults.
    Assert.assertEquals(returnedResults.size(), 3);
    Assert.assertTrue(TestUtils.containsAll(expectedResults, returnedResults));
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 14 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method deleteData.

// table is cleared after each test case
@After
public void deleteData() throws TextDBException {
    RelationManager relationManager = RelationManager.getRelationManager();
    DataWriter oneSentenceDataWriter = relationManager.getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    oneSentenceDataWriter.clearData();
    oneSentenceDataWriter.close();
    DataWriter twoSentenceDataWriter = relationManager.getTableDataWriter(TWO_SENTENCE_TABLE);
    twoSentenceDataWriter.open();
    twoSentenceDataWriter.clearData();
    twoSentenceDataWriter.close();
}
Also used : RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter) After(org.junit.After)

Example 15 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest10.

@Test
public void getNextTupleTest10() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = Arrays.asList(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter) Test(org.junit.Test)

Aggregations

DataWriter (edu.uci.ics.textdb.storage.DataWriter)34 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)31 RelationManager (edu.uci.ics.textdb.storage.RelationManager)18 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 BeforeClass (org.junit.BeforeClass)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 StorageException (edu.uci.ics.textdb.api.exception.StorageException)3 IDField (edu.uci.ics.textdb.api.field.IDField)3 StringField (edu.uci.ics.textdb.api.field.StringField)3 IOException (java.io.IOException)3 File (java.io.File)2 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 IField (edu.uci.ics.textdb.api.field.IField)1 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)1 TextField (edu.uci.ics.textdb.api.field.TextField)1 BufferedReader (java.io.BufferedReader)1 ParseException (java.text.ParseException)1 Scanner (java.util.Scanner)1