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());
}
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;
}
}
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));
}
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);
}
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);
}
Aggregations