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();
}
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);
}
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);
}
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");
}
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\" ");
}
}
Aggregations