use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class TestUtils method testJsonSerialization.
public static JsonNode testJsonSerialization(Object object, boolean printResults) {
try {
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(object);
Object resultObject = objectMapper.readValue(json, object.getClass());
String resultJson = objectMapper.writeValueAsString(resultObject);
JsonNode jsonNode = objectMapper.readValue(json, JsonNode.class);
JsonNode resultJsonNode = objectMapper.readValue(resultJson, JsonNode.class);
if (printResults) {
System.out.println(resultJson);
}
Assert.assertEquals(jsonNode, resultJsonNode);
return jsonNode;
} catch (IOException e) {
throw new TextDBException(e);
}
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class ScanBasedSourceOperator method close.
@Override
public void close() throws TextDBException {
if (!isOpen) {
return;
}
try {
dataReader.close();
isOpen = false;
} catch (Exception e) {
throw new DataFlowException(e.getMessage(), e);
}
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class ExcelSink method open.
@Override
public void open() throws TextDBException {
if (cursor != CLOSED) {
return;
}
inputOperator.open();
inputSchema = inputOperator.getOutputSchema();
outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).filter(attr -> !attr.getAttributeType().equals(AttributeType.LIST)).toArray(Attribute[]::new));
wb = new XSSFWorkbook();
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
fileName = df.format(new Date()) + ".xlsx";
try {
if (Files.notExists(Paths.get(excelIndexDirectory))) {
Files.createDirectories(Paths.get(excelIndexDirectory));
}
fileOut = new FileOutputStream(Paths.get(excelIndexDirectory, fileName).toString());
} catch (IOException e) {
throw new DataFlowException(e);
}
sheet = wb.createSheet("new sheet");
Row row = sheet.createRow(0);
List<String> attributeNames = outputSchema.getAttributeNames();
for (int i = 0; i < attributeNames.size(); i++) {
String attributeName = attributeNames.get(i);
row.createCell(i).setCellValue(attributeName);
}
cursor = OPENED;
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class FuzzyTokenMatcher method processOneInputTuple.
@Override
public Tuple processOneInputTuple(Tuple inputTuple) throws TextDBException {
ListField<Span> payloadField = inputTuple.getField(SchemaConstants.PAYLOAD);
List<Span> payload = payloadField.getValue();
List<Span> relevantSpans = filterRelevantSpans(payload);
List<Span> matchResults = new ArrayList<>();
/*
* The source operator returns spans even for those fields which did not
* satisfy the threshold criterion. So if two attributes A,B have 10 and
* 5 matching tokens, and we set threshold to 10, the number of spans
* returned is 15. So we need to filter those 5 spans for attribute B.
*/
for (String attributeName : this.predicate.getAttributeNames()) {
AttributeType attributeType = this.inputSchema.getAttribute(attributeName).getAttributeType();
// types other than TEXT and STRING: throw Exception for now
if (attributeType != AttributeType.TEXT && attributeType != AttributeType.STRING) {
throw new DataFlowException("FuzzyTokenMatcher: Fields other than TEXT or STRING are not supported");
}
List<Span> fieldSpans = relevantSpans.stream().filter(span -> span.getAttributeName().equals(attributeName)).filter(span -> predicate.getQueryTokens().contains(span.getKey())).collect(Collectors.toList());
if (fieldSpans.size() >= predicate.getThreshold()) {
matchResults.addAll(fieldSpans);
}
}
if (matchResults.isEmpty()) {
return null;
}
ListField<Span> spanListField = inputTuple.getField(predicate.getSpanListName());
List<Span> spanList = spanListField.getValue();
spanList.addAll(matchResults);
return inputTuple;
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class Join method close.
@Override
public void close() throws TextDBException {
if (cursor == CLOSED) {
return;
}
try {
innerOperator.close();
outerOperator.close();
} catch (Exception e) {
throw new DataFlowException(e.getMessage(), e);
}
// Set the inner tuple list back to null on close.
innerTupleList = null;
innerTupleListCursor = 0;
cursor = CLOSED;
}
Aggregations