Search in sources :

Example 1 with DecimalUtils

use of com.b2international.index.util.DecimalUtils in project snow-owl by b2ihealthcare.

the class ReasonerTaxonomyBuilder method addRelationships.

private void addRelationships(final RevisionSearcher searcher, final ExpressionBuilder whereExpressionBuilder, final Builder<StatementFragment> fragmentBuilder) {
    final List<StatementFragment> fragments = new ArrayList<>(SCROLL_LIMIT);
    final String[] lastSourceId = { "" };
    Query.select(String[].class).from(SnomedRelationshipIndexEntry.class).fields(// 0
    SnomedRelationshipIndexEntry.Fields.ID, // 1
    SnomedRelationshipIndexEntry.Fields.SOURCE_ID, // 2
    SnomedRelationshipIndexEntry.Fields.TYPE_ID, // 3
    SnomedRelationshipIndexEntry.Fields.DESTINATION_ID, // 4
    SnomedRelationshipIndexEntry.Fields.DESTINATION_NEGATED, // 5
    SnomedRelationshipIndexEntry.Fields.VALUE_TYPE, // 6
    SnomedRelationshipIndexEntry.Fields.NUMERIC_VALUE, // 7
    SnomedRelationshipIndexEntry.Fields.STRING_VALUE, // 8
    SnomedRelationshipIndexEntry.Fields.RELATIONSHIP_GROUP, // 9
    SnomedRelationshipIndexEntry.Fields.UNION_GROUP, // 10
    SnomedRelationshipIndexEntry.Fields.MODIFIER_ID, // 11
    SnomedRelationshipIndexEntry.Fields.RELEASED).where(whereExpressionBuilder.build()).sortBy(SortBy.builder().sortByField(SnomedRelationshipIndexEntry.Fields.SOURCE_ID, Order.ASC).sortByField(SnomedRelationshipIndexEntry.Fields.ID, Order.ASC).build()).limit(SCROLL_LIMIT).build().stream(searcher).forEachOrdered(hits -> {
        for (final String[] relationship : hits) {
            final String sourceId = relationship[1];
            if (lastSourceId[0].isEmpty()) {
                lastSourceId[0] = sourceId;
            } else if (!lastSourceId[0].equals(sourceId)) {
                if (conceptMap.containsKey(lastSourceId[0])) {
                    fragmentBuilder.putAll(lastSourceId[0], fragments);
                } else {
                    LOGGER.debug("Not registering {} relationships for source concept {} as it is inactive.", fragments.size(), lastSourceId);
                }
                fragments.clear();
                lastSourceId[0] = sourceId;
            }
            final long statementId = Long.parseLong(relationship[0]);
            // final String sourceId = relationship[1];
            final long typeId = Long.parseLong(relationship[2]);
            final Long destinationId = ifNotNull(relationship[3], Long::valueOf);
            final boolean destinationNegated = Boolean.parseBoolean(relationship[4]);
            final RelationshipValueType valueType = ifNotNull(relationship[5], RelationshipValueType::valueOf);
            final BigDecimal decimalValue = ifNotNull(relationship[6], DecimalUtils::decode);
            final String stringValue = relationship[7];
            final int group = Integer.parseInt(relationship[8]);
            final int unionGroup = Integer.parseInt(relationship[9]);
            final boolean universal = Concepts.UNIVERSAL_RESTRICTION_MODIFIER.equals(relationship[10]);
            final boolean released = Boolean.parseBoolean(relationship[11]);
            final StatementFragment statement;
            if (destinationId != null) {
                statement = new StatementFragmentWithDestination(typeId, group, unionGroup, universal, statementId, -1L, released, destinationId, destinationNegated);
            } else {
                final String rawValue = RelationshipValueType.STRING.equals(valueType) ? stringValue : decimalValue.toPlainString();
                statement = new StatementFragmentWithValue(typeId, group, unionGroup, universal, statementId, -1L, released, valueType, rawValue);
            }
            fragments.add(statement);
        }
    });
    if (!lastSourceId[0].isEmpty()) {
        if (conceptMap.containsKey(lastSourceId[0])) {
            fragmentBuilder.putAll(lastSourceId[0], fragments);
        } else {
            LOGGER.debug("Not registering {} relationships for source concept {} as it is inactive.", fragments.size(), lastSourceId);
        }
        fragments.clear();
    }
}
Also used : BigDecimal(java.math.BigDecimal) DecimalUtils(com.b2international.index.util.DecimalUtils)

Aggregations

DecimalUtils (com.b2international.index.util.DecimalUtils)1 BigDecimal (java.math.BigDecimal)1