All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.protege.editor.owl.model.search.SearchResultComparator Maven / Gradle / Ivy

Go to download

OWL ontology editing infrastructure used by the Protege desktop application.

There is a newer version: 5.6.4-beta3
Show newest version
package org.protege.editor.owl.model.search;

import com.google.common.collect.ImmutableList;
import org.protege.editor.owl.OWLEditorKit;

import java.util.Comparator;

/**
 * Author: Matthew Horridge
* Stanford University
* Bio-Medical Informatics Research Group
* Date: 19/09/2012 */ public class SearchResultComparator implements Comparator { public SearchResultComparator(OWLEditorKit editorKit) { } public int compare(SearchResult result1, SearchResult result2) { int catDiff = result1.getCategory().ordinal() - result2.getCategory().ordinal(); if (catDiff != 0) { return catDiff; } int typeDiff = result1.getGroupDescription().compareTo(result2.getGroupDescription()); if (typeDiff != 0) { return typeDiff; } if (isStartOfRenderingMatch(result1)) { if (isStartOfRenderingMatch(result2)) { return compareOWLEntities(result1, result2); } else { return -1; } } else { if (isStartOfRenderingMatch(result2)) { return 1; } else { return compareOWLEntities(result1, result2); } } } private int compareOWLEntities(SearchResult result1, SearchResult result2) { int diff = result1.compareTo(result2); if(diff != 0) { return diff; } String subjectRendering1 = result1.getSubjectRendering(); String subjectRendering2 = result2.getSubjectRendering(); String strippedRendering1 = subjectRendering1.startsWith("'") ? subjectRendering1.substring(1) : subjectRendering1; String strippedRendering2 = subjectRendering2.startsWith("'") ? subjectRendering2.substring(1) : subjectRendering2; return strippedRendering1.compareToIgnoreCase(strippedRendering2); } private boolean isStartOfRenderingMatch(SearchResult searchResult) { if (searchResult.getCategory() != SearchCategory.DISPLAY_NAME) { return false; } String rendering = searchResult.getSearchString(); ImmutableList matches = searchResult.getMatches(); if(matches.isEmpty()) { return false; } SearchResultMatch firstMatch = matches.get(0); if (rendering.startsWith("'")) { return firstMatch.getStart() == 1; } else { return firstMatch.getStart() == 0; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy