use of org.elasticsearch.action.get.GetResponse in project jena by apache.
the class TextIndexESIT method addEntity.
private GetResponse addEntity(Entity entityToAdd) {
classToTest.addEntity(entityToAdd);
GetResponse response = transportClient.prepareGet(INDEX_NAME, DOC_TYPE, entityToAdd.getId()).get();
Assert.assertNotNull(response);
Assert.assertEquals(entityToAdd.getId(), response.getId());
return response;
}
use of org.elasticsearch.action.get.GetResponse in project pyramid by cheng-li.
the class Visualizer method createTable.
private List<Object> createTable(List<Object> data, String fields, Map<String, String> classDescription) throws IOException {
int line_count = 0;
List<Object> output = new ArrayList<>();
for (Object rowData : data) {
final Map<String, Object> row = (Map<String, Object>) rowData;
final Map<String, Object> oneRow = new HashMap<>();
line_count += 1;
final List<Object> r = new ArrayList<>();
final Map<String, Object> idLabels = new HashMap<>();
idLabels.put("id", row.get("id"));
idLabels.put("internalId", row.get("internalId"));
idLabels.put("internalLabels", row.get("internalLabels"));
idLabels.put("feedbackSelect", "none");
idLabels.put("feedbackText", "");
final List<Object> internalLabels = new ArrayList<>();
final Set<String> releLabels = new HashSet<>();
for (int i = 0, rowSize = ((List<Object>) row.get("labels")).size(); i < rowSize; i++) {
Map<Object, Object> label = new HashMap<>();
label.put(((List<Object>) row.get("internalLabels")).get(i), ((List<Object>) row.get("labels")).get(i));
internalLabels.add(label);
releLabels.add(((List<String>) row.get("labels")).get(i));
}
final List<Object> predictions = new ArrayList<>();
final Set<String> pres = new HashSet<>();
for (int i = 0, rowSize = ((List<Object>) row.get("prediction")).size(); i < rowSize; i++) {
Map<Object, Object> label = new HashMap<>();
label.put(((List<Object>) row.get("internalPrediction")).get(i), ((List<Object>) row.get("prediction")).get(i));
predictions.add(label);
pres.add(((List<String>) row.get("prediction")).get(i));
}
idLabels.put("predictions", predictions);
final Set<String> intersections = new HashSet<>(releLabels);
intersections.retainAll(pres);
final Set<String> unions = new HashSet<>(releLabels);
unions.addAll(pres);
if (unions.size() == 0) {
idLabels.put("overlap", "N/A");
} else {
idLabels.put("overlap", String.format("%.2f", (double) intersections.size() / unions.size()));
}
if (releLabels.size() == 0) {
idLabels.put("recall", "N/A");
} else {
idLabels.put("recall", String.format("%.2f", -(double) intersections.size() / releLabels.size()));
}
if (pres.size() == 0) {
idLabels.put("precision", "N/A");
} else {
idLabels.put("precision", (double) intersections.size() / pres.size());
}
oneRow.put("probForPredictedLabels", row.get("probForPredictedLabels"));
oneRow.put("predictedRanking", new ArrayList<>());
for (Map<String, Object> label : (List<Map<String, Object>>) row.get("predictedRanking")) {
final List<Object> curInternalPrediction = (List<Object>) row.get("internalPrediction");
final List<Object> curInternalLabels = (List<Object>) row.get("internalLabels");
final Object labelClassIndex = label.get("classIndex");
if (curInternalLabels.contains(labelClassIndex) && curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "TP");
} else if (!curInternalLabels.contains(labelClassIndex) && curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "FP");
} else if (!curInternalLabels.contains(labelClassIndex) && !curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "FN");
} else {
label.put("type", "");
}
r.add(includesLabel(label.get("className"), internalLabels));
((List<Object>) oneRow.get("predictedRanking")).add(label);
}
for (Map<String, Object> labels : (List<Map<String, Object>>) row.get("predictedLabelSetRanking")) {
labels.put("types", new ArrayList<>());
final List<Object> curInternalLabels = (List<Object>) row.get("internalLabels");
final List<Object> curInternalPrediction = (List<Object>) row.get("internalPrediction");
for (Object index : (List<Object>) labels.get("internalLabels")) {
if (curInternalLabels.contains(index) && curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("TP");
} else if (!curInternalLabels.contains(index) && curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("FP");
} else if (curInternalLabels.contains(index) && !curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("FN");
} else {
((List<Object>) labels.get("types")).add("");
}
}
}
oneRow.put("predictedLabelSetRanking", row.get("predictedLabelSetRanking"));
double sumOfR = 0.0;
double sumOfPrec = 0.0;
int last = 0;
for (int i = 0; i < r.size(); i++) {
if (r.get(i).equals(new Integer(1))) {
sumOfR += (Integer) r.get(i);
sumOfPrec += sumOfR / (i + 1);
last = i + 1;
}
}
if (releLabels.size() == 0) {
idLabels.put("ap", "N/A");
} else {
idLabels.put("ap", String.format("%.2f", sumOfPrec / releLabels.size()));
}
if (sumOfR < releLabels.size()) {
idLabels.put("rankoffullrecall", "N/A");
} else {
idLabels.put("rankoffullrecall", last);
}
oneRow.put("idLabels", idLabels);
GetResponse res = config.getClient().prepareGet(config.getEsIndexName(), "document", (String) row.get("id")).execute().actionGet();
String keys = fields;
oneRow.put("text", new HashMap<String, Map<String, Object>>());
oneRow.put("others", new HashMap<String, Map<String, Object>>());
for (String key : ((Map<String, Object>) res.getContext().get("_source")).keySet()) {
if (keys.equals(key)) {
((Map<String, Object>) oneRow.get("text")).put(key, ((String) ((Map<String, Object>) res.getContext().get("_source")).get(key)).replace("<", "<").replace(">", ">"));
} else {
((Map<String, Object>) oneRow.get("others")).put(key, ((String) ((Map<String, Object>) res.getContext().get("_source")).get(key)));
}
}
createTFPNColumns(row, line_count, oneRow, classDescription);
output.add(oneRow);
}
return output;
}
use of org.elasticsearch.action.get.GetResponse in project play2-elasticsearch by cleverage.
the class IndexService method get.
/**
* Get Indexable Object for an Id
*
* @param indexPath
* @param clazz
* @return
*/
public static <T extends Index> T get(IndexQueryPath indexPath, Class<T> clazz, String id) {
GetRequestBuilder getRequestBuilder = getGetRequestBuilder(indexPath, id);
GetResponse getResponse = getRequestBuilder.execute().actionGet();
return getTFromGetResponse(clazz, getResponse);
}
use of org.elasticsearch.action.get.GetResponse in project crate by crate.
the class GetResponseRefResolver method getImplementation.
@Override
public CollectExpression<GetResponse, ?> getImplementation(Reference ref) {
ColumnIdent columnIdent = ref.ident().columnIdent();
columnConsumer.accept(columnIdent);
String fqn = columnIdent.fqn();
switch(fqn) {
case DocSysColumns.Names.VERSION:
return CollectExpression.of(GetResponse::getVersion);
case DocSysColumns.Names.ID:
return CollectExpression.of(GetResponse::getId);
case DocSysColumns.Names.RAW:
return CollectExpression.of(r -> r.getSourceAsBytesRef().toBytesRef());
case DocSysColumns.Names.DOC:
return CollectExpression.of(GetResponse::getSource);
}
if (docTableInfo.isPartitioned() && docTableInfo.partitionedBy().contains(columnIdent)) {
int pkPos = docTableInfo.primaryKey().indexOf(columnIdent);
if (pkPos >= 0) {
return CollectExpression.of(response -> ValueSymbolVisitor.VALUE.process(ids2Keys.get(response.getId()).values().get(pkPos)));
}
}
return CollectExpression.of(response -> {
Map<String, Object> sourceAsMap = response.getSourceAsMap();
return ref.valueType().value(XContentMapValues.extractValue(fqn, sourceAsMap));
});
}
use of org.elasticsearch.action.get.GetResponse in project crate by crate.
the class ArrayMapperTest method testInsertGetArray.
@Test
public void testInsertGetArray() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("array_field").field("type", ArrayMapper.CONTENT_TYPE).startObject(ArrayMapper.INNER).field("type", "double").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = mapper(INDEX, TYPE, mapping);
IndexResponse response = client().prepareIndex(INDEX, "type").setId("123").setSource("{array_field:[0.0, 99.9, -100.5678]}").execute().actionGet();
assertThat(response.getVersion(), is(1L));
client().admin().indices().prepareRefresh(INDEX).execute().actionGet();
// realtime
GetResponse rtGetResponse = client().prepareGet(INDEX, "type", "123").setFetchSource(true).setFields("array_field").setRealtime(true).execute().actionGet();
assertThat(rtGetResponse.getId(), is("123"));
assertThat(Joiner.on(',').withKeyValueSeparator(":").join(rtGetResponse.getSource()), is("array_field:[0.0, 99.9, -100.5678]"));
assertThat(rtGetResponse.getField("array_field").getValues(), Matchers.<Object>hasItems(0.0D, 99.9D, -100.5678D));
// non-realtime
GetResponse getResponse = client().prepareGet(INDEX, "type", "123").setFetchSource(true).setFields("array_field").setRealtime(false).execute().actionGet();
assertThat(getResponse.getId(), is("123"));
assertThat(Joiner.on(',').withKeyValueSeparator(":").join(getResponse.getSource()), is("array_field:[0.0, 99.9, -100.5678]"));
assertThat(getResponse.getField("array_field").getValues(), Matchers.<Object>hasItems(0.0D, 99.9D, -100.5678D));
}
Aggregations