use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class KrillQuery method _handleAttrGroup.
// Deserialize attribute groups
private SpanQueryWrapper _handleAttrGroup(SpanQueryWrapper elementWithIdWrapper, JsonNode attrNode) throws QueryException {
if (!attrNode.has("relation")) {
throw new QueryException(743, "Term group expects a relation");
}
if (!attrNode.has("operands")) {
throw new QueryException(742, "Term group needs operand list");
}
String relation = attrNode.get("relation").asText();
JsonNode operands = attrNode.get("operands");
SpanQueryWrapper attrWrapper;
if ("relation:and".equals(relation)) {
List<SpanQueryWrapper> wrapperList = new ArrayList<SpanQueryWrapper>();
for (JsonNode operand : operands) {
attrWrapper = _termFromJson(operand);
if (attrWrapper == null) {
throw new QueryException(747, "Attribute is null");
}
wrapperList.add(attrWrapper);
}
if (elementWithIdWrapper != null) {
return new SpanWithAttributeQueryWrapper(elementWithIdWrapper, wrapperList);
} else {
return new SpanWithAttributeQueryWrapper(wrapperList);
}
} else if ("relation:or".equals(relation)) {
SpanAlterQueryWrapper saq = new SpanAlterQueryWrapper(field);
SpanWithAttributeQueryWrapper saqw;
for (JsonNode operand : operands) {
attrWrapper = _termFromJson(operand);
if (attrWrapper == null) {
throw new QueryException(747, "Attribute is null");
}
if (elementWithIdWrapper != null) {
saqw = new SpanWithAttributeQueryWrapper(elementWithIdWrapper, attrWrapper);
} else {
saqw = new SpanWithAttributeQueryWrapper(attrWrapper);
}
saq.or(saqw);
}
return saq;
} else {
throw new QueryException(716, "Unknown relation");
}
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class KrillQuery method _operationRelationFromJson.
private SpanQueryWrapper _operationRelationFromJson(JsonNode operands, JsonNode relation) throws QueryException {
if (operands.size() < 2) {
throw new QueryException(705, "Number of operands is not acceptable");
}
SpanQueryWrapper operand1 = this._fromKoral(operands.get(0), true);
SpanQueryWrapper operand2 = this._fromKoral(operands.get(1), true);
RelationDirection direction;
if (operand1.isEmpty() && !operand2.isEmpty()) {
// "<:";
direction = RelationDirection.LEFT;
} else {
// ">:"
direction = RelationDirection.RIGHT;
}
if (!relation.has("@type")) {
throw new QueryException(701, "JSON-LD group has no @type attribute");
}
if (relation.get("@type").asText().equals("koral:relation")) {
SpanRelationWrapper spanRelationWrapper;
SpanQueryWrapper relationTermWrapper;
if (!relation.has("wrap")) {
throw new QueryException(718, "Missing relation term.");
} else {
relationTermWrapper = _termFromJson(relation.get("wrap"), false, direction);
spanRelationWrapper = new SpanRelationWrapper(relationTermWrapper, operand1, operand2);
}
spanRelationWrapper.setDirection(direction);
return spanRelationWrapper;
} else {
throw new QueryException(713, "Query type is not supported");
}
// if (relation.has("boundary")){
// _operationRepetitionFromJson(relation, operands);
// }
// else{
//
// }
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class KrillQuery method _segFromJson.
// Deserialize koral:token
private SpanQueryWrapper _segFromJson(JsonNode json) throws QueryException {
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
String type = json.get("@type").asText();
if (DEBUG)
log.trace("Wrap new token definition by {}", type);
// Branch on type
switch(type) {
case "koral:term":
// case "match:eq":
return this._termFromJson(json);
case "koral:termGroup":
if (!json.has("operands"))
throw new QueryException(742, "Term group needs operand list");
// Get operands
JsonNode operands = json.get("operands");
SpanSegmentQueryWrapper ssegqw = this.builder().seg();
if (!json.has("relation"))
throw new QueryException(743, "Term group expects a relation");
switch(json.get("relation").asText()) {
case "relation:and":
for (JsonNode operand : operands) {
SpanQueryWrapper part = this._segFromJson(operand);
if (part instanceof SpanAlterQueryWrapper) {
ssegqw.with((SpanAlterQueryWrapper) part);
} else if (part instanceof SpanRegexQueryWrapper) {
ssegqw.with((SpanRegexQueryWrapper) part);
} else if (part instanceof SpanSegmentQueryWrapper) {
ssegqw.with((SpanSegmentQueryWrapper) part);
} else {
throw new QueryException(744, "Operand not supported in term group");
}
;
}
;
return ssegqw;
case "relation:or":
SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
for (JsonNode operand : operands) {
ssaq.or(this._segFromJson(operand));
}
;
return ssaq;
}
;
}
;
throw new QueryException(745, "Token type is not supported");
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestMultipleDistanceIndex method queryJSONwildcardNoFoundry.
@Test
public void queryJSONwildcardNoFoundry() throws QueryException, IOException {
// meine*
ki = new KrillIndex();
ki.addDoc(createFieldDoc5());
ki.commit();
// treat merging gracefully
SpanQueryWrapper sqw = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards_missingfoundry.jsonld").getFile());
SpanQuery sq = sqw.toQuery();
assertEquals(sq.toString(), "SpanMultiTermQueryWrapper(tokens:l:Erfahr*)");
kr = ki.search(sq, (short) 10);
assertEquals(4, kr.getMatches().size());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestReferenceIndex method testCase4.
// multiple document
@Test
public void testCase4() throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.commit();
String filepath = getClass().getResource("/queries/reference/distance-reference.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
kr = ki.search(sq, (short) 10);
assertEquals(4, kr.getTotalResults());
assertEquals("doc-1", kr.getMatch(3).getDocID());
assertEquals(2, kr.getMatch(3).getStartPos());
assertEquals(4, kr.getMatch(3).getEndPos());
}
Aggregations