use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalAxiomsWithValue.
private Promise<Collection<Property>> evalAxiomsWithValue(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, RelationshipValue value, SearchResourceRequest.Operator operator) {
// search existing axioms defined for the given set of conceptIds
ExpressionBuilder axiomFilter = Expressions.builder();
if (typeIds != null) {
axiomFilter.filter(typeIds(typeIds));
}
switch(operator) {
case EQUALS:
axiomFilter.filter(values(List.of(value)));
break;
case GREATER_THAN:
axiomFilter.filter(valueGreaterThan(value, false));
break;
case GREATER_THAN_EQUALS:
axiomFilter.filter(valueGreaterThan(value, true));
break;
case LESS_THAN:
axiomFilter.filter(valueLessThan(value, false));
break;
case LESS_THAN_EQUALS:
axiomFilter.filter(valueLessThan(value, true));
break;
case NOT_EQUALS:
axiomFilter.mustNot(values(List.of(value)));
break;
default:
throw new IllegalStateException("Unexpected operator '" + operator + "'.");
}
ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
if (focusConceptIds != null) {
activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(focusConceptIds));
}
final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow()).build();
final Set<Property> axiomProperties = newHashSet();
context.service(RevisionSearcher.class).stream(activeAxiomStatementsQuery).forEach(chunk -> {
chunk.stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).forEachOrdered(owlMember -> {
owlMember.getClassAxiomRelationships().stream().filter(r -> typeIds == null || typeIds.contains(r.getTypeId())).filter(r -> r.getValueAsObject().matches(operator, value)).map(r -> new Property(owlMember.getReferencedComponentId(), r.getTypeId(), r.getValueAsObject().toObject(), r.getRelationshipGroup())).forEachOrdered(axiomProperties::add);
});
});
return Promise.immediate(axiomProperties);
}
use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.
the class DocumentBuilders method classAxiomsWithValue.
public static SnomedRefSetMemberIndexEntry.Builder classAxiomsWithValue(final String sourceId, final Object... axioms) {
checkArgument(!CompareUtils.isEmpty(axioms), "At least one axiom must be provided");
checkArgument(axioms.length % 3 == 0, "Each axiom should have 3 arguments [typeId:String, value:Integer|Double|String, group:Integer].");
int numberOfAxioms = (int) axioms.length / 3;
final List<SnomedOWLRelationshipDocument> classAxioms = new ArrayList<>(numberOfAxioms);
for (int i = 0; i < numberOfAxioms; i++) {
int offset = i * 3;
final String typeId = (String) axioms[offset];
final Object value = axioms[offset + 1];
final int group = (int) axioms[offset + 2];
final RelationshipValue relationshipValue;
if (value instanceof Integer) {
relationshipValue = new RelationshipValue((Integer) value);
} else if (value instanceof BigDecimal) {
relationshipValue = new RelationshipValue((BigDecimal) value);
} else if (value instanceof String) {
relationshipValue = new RelationshipValue((String) value);
} else {
throw new IllegalArgumentException("Unexpected value <" + value + ">.");
}
classAxioms.add(SnomedOWLRelationshipDocument.createValue(typeId, relationshipValue, group));
}
return classAxioms(sourceId, classAxioms);
}
use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalStatementsWithValue.
private Promise<Collection<Property>> evalStatementsWithValue(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, DataTypeComparison comparison) {
final RelationshipValue value;
final SearchResourceRequest.Operator operator = toSearchOperator(comparison.getOp());
// XXX: no boolean comparison for relationships with value!
if (comparison instanceof BooleanValueComparison) {
return Promise.immediate(List.of());
} else if (comparison instanceof StringValueComparison) {
value = new RelationshipValue(((StringValueComparison) comparison).getValue());
} else if (comparison instanceof IntegerValueComparison) {
value = new RelationshipValue(((IntegerValueComparison) comparison).getValue());
} else if (comparison instanceof DecimalValueComparison) {
value = new RelationshipValue(((DecimalValueComparison) comparison).getValue());
} else {
return SnomedEclEvaluationRequest.throwUnsupported(comparison);
}
return evalStatementsWithValue(context, focusConceptIds, typeIds, value, operator);
}
use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.
the class SnomedRelationshipSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addNamespaceFilter(queryBuilder);
addNamespaceConceptIdFilter(context, queryBuilder);
addEffectiveTimeClause(queryBuilder);
addActiveMemberOfClause(context, queryBuilder);
addMemberOfClause(context, queryBuilder);
addEclFilter(context, queryBuilder, OptionKey.SOURCE, SnomedRelationshipIndexEntry.Expressions::sourceIds);
addEclFilter(context, queryBuilder, OptionKey.TYPE, SnomedRelationshipIndexEntry.Expressions::typeIds);
addEclFilter(context, queryBuilder, OptionKey.DESTINATION, SnomedRelationshipIndexEntry.Expressions::destinationIds);
addEclFilter(context, queryBuilder, OptionKey.CHARACTERISTIC_TYPE, SnomedRelationshipIndexEntry.Expressions::characteristicTypeIds);
addEclFilter(context, queryBuilder, OptionKey.MODIFIER, SnomedRelationshipIndexEntry.Expressions::modifierIds);
if (containsKey(OptionKey.GROUP_MIN) || containsKey(OptionKey.GROUP_MAX)) {
final int from = containsKey(OptionKey.GROUP_MIN) ? get(OptionKey.GROUP_MIN, Integer.class) : 0;
final int to = containsKey(OptionKey.GROUP_MAX) ? get(OptionKey.GROUP_MAX, Integer.class) : Integer.MAX_VALUE;
queryBuilder.filter(relationshipGroup(from, to));
}
if (containsKey(OptionKey.UNION_GROUP)) {
queryBuilder.filter(unionGroup(get(OptionKey.UNION_GROUP, Integer.class)));
}
if (containsKey(OptionKey.HAS_DESTINATION_ID)) {
// No need to check the value for the option key here, as it can only be set to "true" in the builder
queryBuilder.filter(hasDestinationId());
}
if (containsKey(OptionKey.VALUE_TYPE)) {
final Collection<RelationshipValueType> valueTypes = getCollection(OptionKey.VALUE_TYPE, RelationshipValueType.class);
queryBuilder.filter(valueTypes(valueTypes));
}
if (containsKey(OptionKey.VALUE)) {
final SearchResourceRequest.Operator op = get(OptionKey.OPERATOR, SearchResourceRequest.Operator.class);
final Collection<RelationshipValue> values = getCollection(OptionKey.VALUE, RelationshipValue.class);
switch(op) {
case EQUALS:
queryBuilder.filter(values(values));
break;
case NOT_EQUALS:
queryBuilder.mustNot(values(values));
break;
case LESS_THAN:
checkRangeValue(values);
queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), false));
break;
case LESS_THAN_EQUALS:
checkRangeValue(values);
queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), true));
break;
case GREATER_THAN:
checkRangeValue(values);
queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), false));
break;
case GREATER_THAN_EQUALS:
checkRangeValue(values);
queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), true));
break;
default:
throw new NotImplementedException("Unsupported concrete value operator %s", op);
}
}
return queryBuilder.build();
}
use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.
the class SnomedConcreteValueApiTest method createConcreteValueInvalidType.
@Test
public void createConcreteValueInvalidType() {
Json requestBody = createConcreteValueRequestBody(Concepts.ROOT_CONCEPT, "11110000", new RelationshipValue(10)).with("commitComment", "Created new concrete value with invalid typeId");
createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody).statusCode(400);
}
Aggregations