Search in sources :

Example 1 with BROWSING

use of edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING in project webprotege by protegeproject.

the class EntitySearcher method invoke.

/**
 * Invokes the entity searcher to perform a search.
 */
public void invoke() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    matchCounter.reset();
    searchCounter.reset();
    results.clear();
    tagsByLabel.clear();
    tagsManager.getProjectTags().forEach(tag -> tagsByLabel.put(tag.getLabel(), tag));
    tagsByEntity.clear();
    tagsByEntity.putAll(tagsManager.getTags(projectId));
    Pattern searchPattern = compileSearchPattern(searchWords);
    entityStreamSupplier.get().filter(this::isRequiredEntityType).peek(this::incrementSearchCounter).map(this::performMatch).filter(Objects::nonNull).peek(this::incrementMatchCounter).sorted().skip(skip).limit(limit).map(m -> toSearchResult(searchPattern, m)).forEach(results::add);
    logger.info(BROWSING, "{} {} Performed entity search for \"{}\".  Found {} matches in {} entities in {} ms.", projectId, userId, searchString, matchCounter.getCounter(), searchCounter.getCounter(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
Also used : HasGetRendering(edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) Multimap(com.google.common.collect.Multimap) Supplier(java.util.function.Supplier) CASE_INSENSITIVE(java.util.regex.Pattern.CASE_INSENSITIVE) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Obo2OWLConstants(org.obolibrary.obo2owl.Obo2OWLConstants) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) Matcher(java.util.regex.Matcher) IRI(org.semanticweb.owlapi.model.IRI) SearchType(edu.stanford.bmir.protege.web.shared.search.SearchType) Optional(com.google.common.base.Optional) EntityType(org.semanticweb.owlapi.model.EntityType) Nonnull(javax.annotation.Nonnull) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) Nullable(javax.annotation.Nullable) SearchField.displayName(edu.stanford.bmir.protege.web.shared.search.SearchField.displayName) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) TimeUnit(java.util.concurrent.TimeUnit) Stream(java.util.stream.Stream) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult) TagsManager(edu.stanford.bmir.protege.web.server.tag.TagsManager) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Pattern(java.util.regex.Pattern) BROWSING(edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING) Pattern(java.util.regex.Pattern) Stopwatch(com.google.common.base.Stopwatch)

Example 2 with BROWSING

use of edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING in project webprotege by protegeproject.

the class GetIndividualsActionHandler method execute.

@Nonnull
@Override
public GetIndividualsResult execute(@Nonnull GetIndividualsAction action, @Nonnull ExecutionContext executionContext) {
    Stream<OWLNamedIndividual> stream;
    if (action.getType().isOWLThing()) {
        stream = rootOntology.getIndividualsInSignature(Imports.INCLUDED).stream();
    } else {
        stream = rootOntology.getImportsClosure().stream().flatMap(o -> o.getClassAssertionAxioms(action.getType()).stream()).map(OWLClassAssertionAxiom::getIndividual).filter(OWLIndividual::isNamed).map(OWLIndividual::asOWLNamedIndividual);
    }
    Counter counter = new Counter();
    List<OWLNamedIndividualData> individualsData = stream.peek(i -> counter.increment()).map(renderingManager::getRendering).filter(i -> {
        String searchString = action.getFilterString();
        return searchString.isEmpty() || StringUtils.containsIgnoreCase(i.getBrowserText(), searchString);
    }).distinct().sorted().collect(toList());
    PageRequest pageRequest = action.getPageRequest();
    Pager<OWLNamedIndividualData> pager = Pager.getPagerForPageSize(individualsData, pageRequest.getPageSize());
    Page<OWLNamedIndividualData> page = pager.getPage(pageRequest.getPageNumber());
    OWLClassData type = renderingManager.getRendering(action.getType());
    logger.info(BROWSING, "{} {} retrieved instances of {} ({})", projectId, executionContext.getUserId(), action.getType(), renderingManager.getRendering(action.getType()).getBrowserText());
    return new GetIndividualsResult(type, page, counter.getCount(), individualsData.size());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) LoggerFactory(org.slf4j.LoggerFactory) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) Inject(javax.inject.Inject) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) RenderingManager(edu.stanford.bmir.protege.web.server.renderer.RenderingManager) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) Imports(org.semanticweb.owlapi.model.parameters.Imports) Logger(org.slf4j.Logger) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) GetIndividualsAction(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsAction) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) BROWSING(edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) Nonnull(javax.annotation.Nonnull)

Aggregations

BROWSING (edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING)2 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)2 Stream (java.util.stream.Stream)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 StringUtils (org.apache.commons.lang.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Optional (com.google.common.base.Optional)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Stopwatch (com.google.common.base.Stopwatch)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)1 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)1 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)1 RootOntology (edu.stanford.bmir.protege.web.server.inject.project.RootOntology)1 HasGetRendering (edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering)1 Pager (edu.stanford.bmir.protege.web.server.pagination.Pager)1