use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class SemanticSearchServiceHelper method getAttributeIdentifiers.
/**
* A helper function that gets identifiers of all the attributes from one EntityType
*/
public List<String> getAttributeIdentifiers(EntityType sourceEntityType) {
Entity EntityTypeEntity = dataService.findOne(ENTITY_TYPE_META_DATA, new QueryImpl<>().eq(EntityTypeMetadata.ID, sourceEntityType.getId()));
if (EntityTypeEntity == null)
throw new MolgenisDataAccessException("Could not find EntityTypeEntity by the name of " + sourceEntityType.getId());
List<String> attributeIdentifiers = new ArrayList<>();
recursivelyCollectAttributeIdentifiers(EntityTypeEntity.getEntities(EntityTypeMetadata.ATTRIBUTES), attributeIdentifiers);
return attributeIdentifiers;
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class UntypedTagService method getTagsForPackage.
@Override
@RunAsSystem
public Iterable<SemanticTag<Package, LabeledResource, LabeledResource>> getTagsForPackage(Package p) {
Entity packageEntity = dataService.findOne(PACKAGE, new QueryImpl<>().eq(PackageMetadata.ID, p.getId()));
if (packageEntity == null) {
throw new UnknownEntityException("Unknown package [" + p.getId() + "]");
}
List<SemanticTag<Package, LabeledResource, LabeledResource>> tags = Lists.newArrayList();
for (Entity tagEntity : packageEntity.getEntities(PackageMetadata.TAGS)) {
tags.add(SemanticTag.asTag(p, tagEntity));
}
return tags;
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class DynamicRepositoryDecoratorRegistryImpl method decorate.
@Override
public synchronized Repository<Entity> decorate(Repository<Entity> repository) {
String entityTypeId = repository.getEntityType().getId();
if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) {
Query query = new QueryImpl().eq(ENTITY_TYPE_ID, entityTypeId);
DecoratorConfiguration configuration = dataService.findOne(DECORATOR_CONFIGURATION, query, DecoratorConfiguration.class);
if (configuration != null) {
repository = decorateRepository(repository, configuration);
}
}
return repository;
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracksAll.
@Test
public void testGetReferenceTracksAll() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
when(molgenisEntity.getLabel()).thenReturn("label");
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
GenomeBrowserAttributes attrs1 = getGenomeBrowserAttributes("pos", "chr", "ref", "alt");
GenomeBrowserAttributes attrs2 = getGenomeBrowserAttributes("POS", "CHROM", null, null);
when(dataService.findAll(GenomeBrowserAttributesMetadata.GENOMEBROWSERATTRIBUTES, new QueryImpl<GenomeBrowserAttributes>().eq(GenomeBrowserAttributesMetadata.DEFAULT, true), GenomeBrowserAttributes.class)).thenReturn(Stream.of(attrs1, attrs2));
EntityType type1 = mock(EntityType.class);
EntityType type2 = mock(EntityType.class);
EntityType type3 = mock(EntityType.class);
Attribute labelAttr = mock(Attribute.class);
when(labelAttr.getName()).thenReturn("refLabel");
List<EntityType> types = new ArrayList<>();
types.add(type1);
when(type1.getIdValue()).thenReturn("type1");
when(type1.getLabel()).thenReturn("label1");
when(type1.getAttributeNames()).thenReturn(Arrays.asList("POS", "CHROM", "AAP", "NOOT", "MIES"));
when(type1.getLabelAttribute()).thenReturn(labelAttr);
types.add(type2);
when(type2.getIdValue()).thenReturn("type2");
when(type2.getLabel()).thenReturn("label2");
when(type2.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alt", "aap"));
when(type2.getLabelAttribute()).thenReturn(labelAttr);
types.add(type3);
when(type3.getIdValue()).thenReturn("type3");
when(type3.getLabel()).thenReturn("label3");
when(type3.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alternative", "monkey"));
when(type3.getLabelAttribute()).thenReturn(labelAttr);
MetaDataService metaDataService = mock(MetaDataService.class);
when(dataService.getMeta()).thenReturn(metaDataService);
when(metaDataService.getEntityTypes()).thenReturn(types.stream());
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 2);
assertEquals(result.get("type2"), GenomeBrowserTrack.create("type2", "label2", "refLabel", type2, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs1, null, null, null, null));
assertEquals(result.get("type1"), GenomeBrowserTrack.create("type1", "label1", "refLabel", type1, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs2, null, null, null, null));
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class SearchServiceIT method testSemanticSearch.
@Test
public void testSemanticSearch() {
List<Entity> attributes = createDynamic(6).collect(toList());
attributes.get(0).set(ATTR_STRING, "High chance of pulmonary disease");
attributes.get(1).set(ATTR_STRING, "And now for something completely different...");
attributes.get(2).set(ATTR_STRING, "Are you taking hypertensive medication?");
attributes.get(3).set(ATTR_STRING, "Have you ever had high blood pressure? (Repeat) (1)");
attributes.get(4).set(ATTR_STRING, "Do you suffer from Ocular hypertension?");
attributes.get(5).set(ATTR_STRING, "Do you have a vascular disorder?");
Entity ontology1 = attributes.get(0).getEntity(ATTR_CATEGORICAL);
Entity ontology2 = attributes.get(1).getEntity(ATTR_CATEGORICAL);
for (Entity term : attributes) {
term.set(ATTR_CATEGORICAL, ontology1);
}
attributes.get(5).set(ATTR_CATEGORICAL, ontology2);
searchService.index(entityTypeDynamic, attributes.stream());
searchService.refreshIndex();
List<String> queryTerms = asList("hypertension", "disorder vascular hypertensive", "increased pressure blood", "high pressure blood", "ocular^0.5 hypertension^0.5", "hypertension^0.25 idiopathic^0.25 pulmonary^0.25");
QueryRule finalDisMaxQuery = new QueryRule(queryTerms.stream().flatMap(term -> Stream.of(new QueryRule(ATTR_STRING, FUZZY_MATCH, term), new QueryRule(ATTR_SCRIPT, FUZZY_MATCH, term))).collect(toList()));
finalDisMaxQuery.setOperator(DIS_MAX);
List<String> attributeIds = asList("0", "1", "2", "3", "4", "5");
Query<Entity> query = new QueryImpl<>(asList(new QueryRule(ATTR_ID, IN, attributeIds), new QueryRule(AND), finalDisMaxQuery));
List<Object> matchingAttributeIDs = searchService.search(entityTypeDynamic, query).collect(toList());
assertEquals(matchingAttributeIDs.get(0), "3");
assertEquals(matchingAttributeIDs.get(1), "5");
assertFalse(matchingAttributeIDs.contains("1"));
List<Explanation> explanations = attributeIds.stream().map(id -> explainService.explain(query, entityTypeDynamic, id)).collect(toList());
List<Float> scores = explanations.stream().map(Explanation::getValue).collect(toList());
// FIXME these scores vary between runs
// assertEquals(scores, asList(0.3463153, 0, 0.7889965, 1.7814579, 0.76421005, 1.0707202));
Map<String, String> expandedQueryMap = new HashMap<>();
for (String term : asList("hypertens", "disord vascular hypertens", "increased pressur blood", "high pressur blood", "ocular hypertens", "hypertens idiopathic pulmonary")) {
expandedQueryMap.put(term, "hypertension");
}
List<Set<ExplainedQueryString>> explanationStrings = explanations.stream().map(explanation -> explainService.findQueriesFromExplanation(expandedQueryMap, explanation)).collect(toList());
List<Set<ExplainedQueryString>> expectedExplanationStrings = asList(// High chance of pulmonary disease
singleton(ExplainedQueryString.create("high", "high pressur blood", "hypertension", 41.66666666666667)), // And now for something completely different...
emptySet(), // Are you taking hypertensive medication?
singleton(ExplainedQueryString.create("hypertens", "hypertens", "hypertension", 100.0)), // Have you ever had high blood pressure? (Repeat) (1)
singleton(ExplainedQueryString.create("high pressur blood", "high pressur blood", "hypertension", 100.0)), // Do you suffer from Ocular hypertension?
singleton(ExplainedQueryString.create("ocular hypertens", "ocular hypertens", "hypertension", 100.0)), // Do you have a vascular disorder?
singleton(ExplainedQueryString.create("disord vascular", "disord vascular hypertens", "hypertension", 78.04878048780488)));
assertEquals(explanationStrings, expectedExplanationStrings);
}
Aggregations