Search in sources :

Example 11 with StringField

use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.

the class RelationManagerTest method test8.

/*
     * Test inserting a tuple to a table and then delete it 
     */
@Test
public void test8() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getInstance();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
    IDField idField = dataWriter.insertTuple(insertedTuple);
    dataWriter.close();
    Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
    dataWriter.open();
    dataWriter.deleteTupleByID(idField);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) StringField(edu.uci.ics.texera.api.field.StringField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 12 with StringField

use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.

the class TwitterJsonConverterTest method getAllSampleTwitterTuples.

public static List<Tuple> getAllSampleTwitterTuples() throws Exception {
    // read the JSON file into a list of JSON string tuples
    JsonNode jsonNode = new ObjectMapper().readTree(new File(twitterFilePath));
    ArrayList<Tuple> jsonStringTupleList = new ArrayList<>();
    Schema tupleSourceSchema = new Schema(SchemaConstants._ID_ATTRIBUTE, new Attribute("twitterJson", AttributeType.STRING));
    for (JsonNode tweet : jsonNode) {
        Tuple tuple = new Tuple(tupleSourceSchema, IDField.newRandomID(), new StringField(tweet.toString()));
        jsonStringTupleList.add(tuple);
    }
    // setup the twitter converter DAG
    // TupleSource --> TwitterJsonConverter --> TupleSink
    TupleSourceOperator tupleSource = new TupleSourceOperator(jsonStringTupleList, tupleSourceSchema);
    TwitterJsonConverter twitterJsonConverter = new TwitterJsonConverterPredicate("twitterJson").newOperator();
    TupleSink tupleSink = new TupleSinkPredicate(null, null).newOperator();
    twitterJsonConverter.setInputOperator(tupleSource);
    tupleSink.setInputOperator(twitterJsonConverter);
    tupleSink.open();
    List<Tuple> tuples = tupleSink.collectAllTuples();
    tupleSink.close();
    return tuples;
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) Attribute(edu.uci.ics.texera.api.schema.Attribute) TwitterJsonConverterPredicate(edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverterPredicate) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) TwitterJsonConverter(edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverter) TupleSinkPredicate(edu.uci.ics.texera.dataflow.sink.tuple.TupleSinkPredicate) StringField(edu.uci.ics.texera.api.field.StringField) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 13 with StringField

use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.

the class SampleExtraction method parsePromedHTML.

public static Tuple parsePromedHTML(String fileName, String content) {
    try {
        Document parsedDocument = Jsoup.parse(content);
        String mainText = parsedDocument.getElementById("preview").text();
        Tuple tuple = new Tuple(PromedSchema.PROMED_SCHEMA, new StringField(fileName), new TextField(mainText));
        return tuple;
    } catch (Exception e) {
        return null;
    }
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) Document(org.jsoup.nodes.Document) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 14 with StringField

use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.

the class TwitterSample method writeTwitterIndex.

/**
 * Writes the sample twitter data into the twitter_sample table
 * @throws Exception
 */
public static void writeTwitterIndex() throws Exception {
    // read the JSON file into a list of JSON string tuples
    JsonNode jsonNode = new ObjectMapper().readTree(new File(twitterFilePath));
    ArrayList<Tuple> jsonStringTupleList = new ArrayList<>();
    Schema tupleSourceSchema = new Schema(new Attribute("twitterJson", AttributeType.STRING));
    for (JsonNode tweet : jsonNode) {
        Tuple tuple = new Tuple(tupleSourceSchema, new StringField(tweet.toString()));
        jsonStringTupleList.add(tuple);
    }
    // setup the twitter converter DAG
    // TupleSource --> TwitterJsonConverter --> TupleSink
    TupleSourceOperator tupleSource = new TupleSourceOperator(jsonStringTupleList, tupleSourceSchema, false);
    createTwitterTable(twitterClimateTable, tupleSource);
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) StringField(edu.uci.ics.texera.api.field.StringField) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 15 with StringField

use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.

the class ExcelSinkTest method attributeTypeTest.

@Test
public // writing 10000 tuples
void attributeTypeTest() throws Exception {
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.AGE);
    attributeNames.add(TestConstants.HEIGHT);
    attributeNames.add(TestConstants.DATE_OF_BIRTH);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare Schema
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length];
    for (int count = 0; count < schemaAttributes.length; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    // Prepare 10000 tuples as a tupleList
    int testSize = 10000;
    Random rand = new Random();
    List<Tuple> tupleList = new ArrayList<Tuple>();
    for (int i = 0; i < testSize; i++) {
        IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble() * rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString()) };
        tupleList.add(new Tuple(new Schema(schemaAttributes), fields));
    }
    assert (tupleList.size() == testSize);
    IOperator inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    // excel writing test
    excelSink = new ExcelSink(new ExcelSinkPredicate());
    excelSink.setInputOperator(inputOperator);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    Files.deleteIfExists(excelSink.getFilePath());
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Random(java.util.Random) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Test(org.junit.Test)

Aggregations

StringField (edu.uci.ics.texera.api.field.StringField)103 Tuple (edu.uci.ics.texera.api.tuple.Tuple)94 IField (edu.uci.ics.texera.api.field.IField)87 IntegerField (edu.uci.ics.texera.api.field.IntegerField)87 TextField (edu.uci.ics.texera.api.field.TextField)79 Schema (edu.uci.ics.texera.api.schema.Schema)75 ArrayList (java.util.ArrayList)74 Test (org.junit.Test)70 Span (edu.uci.ics.texera.api.span.Span)64 DoubleField (edu.uci.ics.texera.api.field.DoubleField)63 DateField (edu.uci.ics.texera.api.field.DateField)60 Attribute (edu.uci.ics.texera.api.schema.Attribute)60 SimpleDateFormat (java.text.SimpleDateFormat)58 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 IDField (edu.uci.ics.texera.api.field.IDField)5 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)4