Search in sources :

Example 26 with RelationManager

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

the class RegexMatcherTestHelper 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.nGramAnalyzerString(3));
    DataWriter peopleDataWriter = relationManager.getTableDataWriter(PEOPLE_TABLE);
    peopleDataWriter.open();
    for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
        peopleDataWriter.insertTuple(tuple);
    }
    peopleDataWriter.close();
    // create the corporation table and write tuples
    relationManager.createTable(CORP_TABLE, "../index/test_tables/" + CORP_TABLE, RegexTestConstantsCorp.SCHEMA_CORP, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter corpDataWriter = relationManager.getTableDataWriter(CORP_TABLE);
    corpDataWriter.open();
    for (Tuple tuple : RegexTestConstantsCorp.getSampleCorpTuples()) {
        corpDataWriter.insertTuple(tuple);
    }
    corpDataWriter.close();
    // create the staff table
    relationManager.createTable(STAFF_TABLE, "../index/tests/" + STAFF_TABLE, RegexTestConstantStaff.SCHEMA_STAFF, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter staffDataWriter = relationManager.getTableDataWriter(STAFF_TABLE);
    staffDataWriter.open();
    for (Tuple tuple : RegexTestConstantStaff.getSampleStaffTuples()) {
        staffDataWriter.insertTuple(tuple);
    }
    staffDataWriter.close();
    // create the text table
    relationManager.createTable(TEXT_TABLE, "../index/tests/" + TEXT_TABLE, RegexTestConstantsText.SCHEMA_TEXT, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter textDataWriter = relationManager.getTableDataWriter(TEXT_TABLE);
    textDataWriter.open();
    for (Tuple tuple : RegexTestConstantsText.getSampleTextTuples()) {
        textDataWriter.insertTuple(tuple);
    }
    textDataWriter.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 27 with RelationManager

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

the class RegexMatcherTestHelper method deleteTestTables.

public static void deleteTestTables() throws TextDBException {
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(PEOPLE_TABLE);
    relationManager.deleteTable(CORP_TABLE);
    relationManager.deleteTable(STAFF_TABLE);
    relationManager.deleteTable(TEXT_TABLE);
}
Also used : RelationManager(edu.uci.ics.textdb.storage.RelationManager)

Example 28 with RelationManager

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

the class NlpEntityTest method cleanUp.

@AfterClass
public static void cleanUp() throws Exception {
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(ONE_SENTENCE_TABLE);
    relationManager.deleteTable(TWO_SENTENCE_TABLE);
}
Also used : RelationManager(edu.uci.ics.textdb.storage.RelationManager) AfterClass(org.junit.AfterClass)

Example 29 with RelationManager

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

the class TwitterSample method writeTwitterIndex.

public static void writeTwitterIndex() throws Exception {
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(twitterClimateTable);
    relationManager.createTable(twitterClimateTable, "../index/twitter/", TwitterSchema.TWITTER_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(twitterClimateTable);
    dataWriter.open();
    int counter = 0;
    JsonNode jsonNode = new ObjectMapper().readTree(new File(twitterFilePath));
    for (JsonNode tweet : jsonNode) {
        try {
            String text = tweet.get("text").asText();
            Long id = tweet.get("id").asLong();
            String tweetLink = "https://twitter.com/statuses/" + id;
            JsonNode userNode = tweet.get("user");
            String userScreenName = userNode.get("screen_name").asText();
            String userLink = "https://twitter.com/" + userScreenName;
            String userName = userNode.get("name").asText();
            String userDescription = userNode.get("description").asText();
            Integer userFollowersCount = userNode.get("followers_count").asInt();
            Integer userFriendsCount = userNode.get("friends_count").asInt();
            JsonNode geoTagNode = tweet.get("geo_tag");
            String state = geoTagNode.get("stateName").asText();
            String county = geoTagNode.get("countyName").asText();
            String city = geoTagNode.get("cityName").asText();
            String createAt = tweet.get("create_at").asText();
            Tuple tuple = new Tuple(TwitterSchema.TWITTER_SCHEMA, new TextField(text), new StringField(tweetLink), new StringField(userLink), new TextField(userScreenName), new TextField(userName), new TextField(userDescription), new IntegerField(userFollowersCount), new IntegerField(userFriendsCount), new TextField(state), new TextField(county), new TextField(city), new StringField(createAt));
            dataWriter.insertTuple(tuple);
            counter++;
        } catch (RuntimeException e) {
            e.printStackTrace();
            continue;
        }
    }
    dataWriter.close();
    System.out.println("write twitter data finished");
    System.out.println(counter + " tweets written");
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 30 with RelationManager

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

the class PerfTestUtils method writeIndex.

/**
     * Writes a data file into an index
     * 
     * @param fileName,
     *            data file
     * @param luceneAnalyzer
     * @param indexType,
     *            indicates the types of index, trigram or standard
     * @throws Exception
     */
public static void writeIndex(String fileName, Analyzer luceneAnalyzer, String indexType) throws Exception {
    RelationManager relationManager = RelationManager.getRelationManager();
    String tableName = fileName.replace(".txt", "");
    if (indexType.equalsIgnoreCase("trigram")) {
        tableName = tableName + "_trigram";
        relationManager.deleteTable(tableName);
        relationManager.createTable(tableName, getTrigramIndexPath(tableName).toString(), MedlineIndexWriter.SCHEMA_MEDLINE, LuceneAnalyzerConstants.nGramAnalyzerString(3));
        MedlineIndexWriter.writeMedlineIndex(Paths.get(fileFolder, fileName), tableName);
    } else if (indexType.equalsIgnoreCase("standard")) {
        relationManager.deleteTable(tableName);
        relationManager.createTable(tableName, getIndexPath(tableName).toString(), MedlineIndexWriter.SCHEMA_MEDLINE, LuceneAnalyzerConstants.standardAnalyzerString());
        MedlineIndexWriter.writeMedlineIndex(Paths.get(fileFolder, fileName), tableName);
    } else {
        System.out.println("Index is not successfully written.");
        System.out.println("IndexType has to be either \"standard\" or \"trigram\"  ");
    }
}
Also used : RelationManager(edu.uci.ics.textdb.storage.RelationManager)

Aggregations

RelationManager (edu.uci.ics.textdb.storage.RelationManager)35 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)19 DataWriter (edu.uci.ics.textdb.storage.DataWriter)18 BeforeClass (org.junit.BeforeClass)8 ArrayList (java.util.ArrayList)5 AfterClass (org.junit.AfterClass)5 ScanBasedSourceOperator (edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator)2 ScanSourcePredicate (edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate)2 File (java.io.File)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StorageException (edu.uci.ics.textdb.api.exception.StorageException)1 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)1 StringField (edu.uci.ics.textdb.api.field.StringField)1 TextField (edu.uci.ics.textdb.api.field.TextField)1 DictionaryPredicate (edu.uci.ics.textdb.exp.dictionarymatcher.DictionaryPredicate)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Scanner (java.util.Scanner)1