<commit_before>import com.b2international.index.Hits
import com.b2international.index.aggregations.Aggregation
import com.b2international.index.aggregations.AggregationBuilder
import com.b2international.index.query.Expression
import com.b2international.index.query.Expressions
import com.b2international.index.query.Query
import com.b2international.index.revision.RevisionSearcher
import com.b2international.snowowl.core.ComponentIdentifier
import com.b2international.snowowl.snomed.SnomedConstants.Concepts
import com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry
import com.google.common.collect.Lists
import com.google.common.collect.Sets


Hits<String> conceptHits = ctx.service(RevisionSearcher.class)
		.search(Query.select(String.class)
		.from(SnomedConceptDocument.class)
		.fields(SnomedConceptDocument.Fields.ID)
		.where(SnomedConceptDocument.Expressions.active())
		.limit(Integer.MAX_VALUE)
		.build())
		
Set<String> conceptIds = Sets.newHashSet(conceptHits)

Expression expression = Expressions
		.builder()
		.filter(SnomedDescriptionIndexEntry.Expressions.active())
		.filter(SnomedDescriptionIndexEntry.Expressions.type(Concepts.FULLY_SPECIFIED_NAME))
		.filter(SnomedDescriptionIndexEntry.Expressions.concepts(conceptIds))
		.build()

Aggregation<SnomedDescriptionIndexEntry> buckets = ctx.service(RevisionSearcher.class)
		.aggregate(AggregationBuilder
		.bucket("ruleSnomedCommon2", SnomedDescriptionIndexEntry.class)
		.query(expression)
		.onFieldValue(SnomedDescriptionIndexEntry.Fields.ORIGINAL_TERM)
		.minBucketSize(2))

List<ComponentIdentifier> invalidIds = Lists.newArrayList()

buckets.getBuckets().values().each({ bucket ->
	bucket.each({ entry ->
		invalidIds.add(ComponentIdentifier.of(SnomedTerminologyComponentConstants.DESCRIPTION_NUMBER, entry.getId()))
	})
})

return invalidIds;<commit_msg>[validation] fix invalid return type of ruleSnomedCommon2 script rule<commit_after>import com.b2international.index.Hits
import com.b2international.index.aggregations.Aggregation
import com.b2international.index.aggregations.AggregationBuilder
import com.b2international.index.query.Expression
import com.b2international.index.query.Expressions
import com.b2international.index.query.Query
import com.b2international.index.revision.RevisionSearcher
import com.b2international.snowowl.core.ComponentIdentifier
import com.b2international.snowowl.core.validation.issue.IssueDetail
import com.b2international.snowowl.snomed.SnomedConstants.Concepts
import com.b2international.snowowl.snomed.common.SnomedRf2Headers
import com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry
import com.google.common.collect.ImmutableMap
import com.google.common.collect.Lists
import com.google.common.collect.Sets


Hits<String> conceptHits = ctx.service(RevisionSearcher.class)
		.search(Query.select(String.class)
		.from(SnomedConceptDocument.class)
		.fields(SnomedConceptDocument.Fields.ID)
		.where(SnomedConceptDocument.Expressions.active())
		.limit(Integer.MAX_VALUE)
		.build())
		
Set<String> conceptIds = Sets.newHashSet(conceptHits)

Expression expression = Expressions
		.builder()
		.filter(SnomedDescriptionIndexEntry.Expressions.active())
		.filter(SnomedDescriptionIndexEntry.Expressions.type(Concepts.FULLY_SPECIFIED_NAME))
		.filter(SnomedDescriptionIndexEntry.Expressions.concepts(conceptIds))
		.build()

Aggregation<SnomedDescriptionIndexEntry> buckets = ctx.service(RevisionSearcher.class)
		.aggregate(AggregationBuilder
		.bucket("ruleSnomedCommon2", SnomedDescriptionIndexEntry.class)
		.query(expression)
		.onFieldValue(SnomedDescriptionIndexEntry.Fields.ORIGINAL_TERM)
		.minBucketSize(2))

List<IssueDetail> issues = Lists.newArrayList()

buckets.getBuckets().values().each({ bucket ->
	bucket.each({ entry ->
		issues.add(
			new IssueDetail(
				ComponentIdentifier.of(SnomedTerminologyComponentConstants.DESCRIPTION_NUMBER, entry.getId()),
				ImmutableMap.of(
					SnomedRf2Headers.FIELD_MODULE_ID, entry.getModuleId(),
					SnomedRf2Headers.FIELD_ACTIVE, entry.isActive()
				)
			)
		)
	})
})

return issues;
{'fraction_non_alphanumeric': 0.09899216125419932, 'fraction_numerical': 0.00761478163493841, 'mean_word_length': 7.17948717948718, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1379537', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1358, 'n_words': 157}