Search in sources :

Example 1 with Tag

use of edu.stanford.bmir.protege.web.shared.tag.Tag in project webprotege by protegeproject.

the class EntitySearcher method toSearchResult.

private EntitySearchResult toSearchResult(Pattern searchPattern, SearchMatch ren) {
    OWLEntityData ed = ren.getEntityData();
    String rendering = ed.getBrowserText();
    StringBuilder highlighted = new StringBuilder();
    highlightSearchResult(searchPattern, rendering, highlighted);
    if (ren.getMatchType() == MatchType.IRI) {
        // Matched the IRI remainder
        highlighted.append("<div class=\"searchedIri\">");
        IRI iri = ed.getEntity().getIRI();
        highlightSearchResult(searchPattern, iri.toString(), highlighted);
        highlighted.append("</div>");
    }
    if (ren.getMatchType() == MatchType.TAG) {
        for (Tag tag : tagsByEntity.get(ed.getEntity())) {
            if (searchString.equalsIgnoreCase(tag.getLabel())) {
                highlighted.append("<div class='wp-tag wp-tag--inline-tag' style='display: inline-block; color: ").append(tag.getColor().getHex()).append("; background-color:").append(tag.getBackgroundColor().getHex()).append(";'>");
                highlighted.append(tag.getLabel());
                highlighted.append("</div>");
            }
        }
    }
    return new EntitySearchResult(ed, displayName(), highlighted.toString());
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)

Example 2 with Tag

use of edu.stanford.bmir.protege.web.shared.tag.Tag in project webprotege by protegeproject.

the class EntitySearcher method performMatch.

@Nullable
private SearchMatch performMatch(@Nonnull OWLEntity e) {
    OWLEntityData rendering = renderingSupplier.getRendering(e);
    MatchType matchType = null;
    if (tagsByLabel.containsKey(searchString)) {
        for (Tag tag : tagsByEntity.get(e)) {
            if (tag.getLabel().equals(searchString)) {
                matchType = MatchType.TAG;
                break;
            }
        }
    }
    if (matchType == null) {
        matchType = MatchType.RENDERING;
        // All search words must be found
        for (String searchWord : searchWords) {
            if (!StringUtils.containsIgnoreCase(rendering.getBrowserText(), searchWord)) {
                matchType = null;
                break;
            }
        }
    }
    // If we didn't match the rendering then search the IRI remainder
    IRI entityIri = rendering.getEntity().getIRI();
    if (matchType == null && entityIri.toString().startsWith(Obo2OWLConstants.DEFAULT_IRI_PREFIX)) {
        matchType = MatchType.IRI;
        Optional<String> remainder = entityIri.getRemainder();
        if (remainder.isPresent()) {
            for (String searchWord : searchWords) {
                if (!StringUtils.containsIgnoreCase(remainder.get(), searchWord)) {
                    matchType = null;
                    break;
                }
            }
        }
    }
    if (matchType != null) {
        return new SearchMatch(searchWords, rendering, matchType);
    } else {
        return null;
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) Nullable(javax.annotation.Nullable)

Example 3 with Tag

use of edu.stanford.bmir.protege.web.shared.tag.Tag 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 4 with Tag

use of edu.stanford.bmir.protege.web.shared.tag.Tag in project webprotege by protegeproject.

the class TagRepository_IT method setUp.

@Before
public void setUp() throws Exception {
    client = createMongoClient();
    Morphia morphia = createMorphia();
    Datastore datastore = morphia.createDatastore(client, getTestDbName());
    repository = new TagRepository(datastore);
    repository.ensureIndexes();
    tagId = TagId.getId("12345678-1234-1234-1234-123456789abc");
    projectId = ProjectId.get("12345678-1234-1234-1234-123456789abc");
    tag = new Tag(tagId, projectId, THE_TAG_LABEL, THE_TAG_DESCRIPTION, COLOR, BG_COLOR);
    repository.saveTag(tag);
}
Also used : MongoTestUtils.createMorphia(edu.stanford.bmir.protege.web.server.persistence.MongoTestUtils.createMorphia) Morphia(org.mongodb.morphia.Morphia) Datastore(org.mongodb.morphia.Datastore) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) Before(org.junit.Before)

Example 5 with Tag

use of edu.stanford.bmir.protege.web.shared.tag.Tag in project webprotege by protegeproject.

the class TagRepository_IT method shouldNotSaveTagWithDuplicateLabel.

@Test(expected = DuplicateKeyException.class)
public void shouldNotSaveTagWithDuplicateLabel() {
    TagId otherTagId = TagId.getId("1234abcd-abcd-abcd-abcd-123456789abc");
    Tag otherTag = new Tag(otherTagId, projectId, THE_TAG_LABEL, THE_TAG_DESCRIPTION, COLOR, BG_COLOR);
    repository.saveTag(otherTag);
}
Also used : TagId(edu.stanford.bmir.protege.web.shared.tag.TagId) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) Test(org.junit.Test)

Aggregations

Tag (edu.stanford.bmir.protege.web.shared.tag.Tag)7 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)3 IRI (org.semanticweb.owlapi.model.IRI)3 EntitySearchResult (edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)2 Nullable (javax.annotation.Nullable)2 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)2 Test (org.junit.Test)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 DataResource (com.google.gwt.resources.client.DataResource)1 BROWSING (edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING)1 HasGetRendering (edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering)1 MongoTestUtils.createMorphia (edu.stanford.bmir.protege.web.server.persistence.MongoTestUtils.createMorphia)1 TagsManager (edu.stanford.bmir.protege.web.server.tag.TagsManager)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 SearchField.displayName (edu.stanford.bmir.protege.web.shared.search.SearchField.displayName)1