Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implemented prefix filter, #76

Merged
merged 1 commit into from Mar 24, 2017
Jump to file or symbol
Failed to load files and symbols.
+52 −8
Split
@@ -95,14 +95,22 @@ else if (filter instanceof TypeFilter) {
int ix = knowledgeBase.getClassIndex(tf.getTypeId());
return typesBM.getPositions().contains(ix) ^ tf.isNegated();
}
- else if (filter instanceof IdFilter) {
- IdFilter idf = (IdFilter)filter;
- if (idf.getIds().contains(id)) {
- return true;
- } else {
- return false;
- }
- }
+ else if (filter instanceof IdFilter) {
+ IdFilter idf = (IdFilter)filter;
+ if (idf.getIds().contains(id)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ else if (filter instanceof IdPrefixFilter) {
+ IdPrefixFilter idf = (IdPrefixFilter)filter;
+ if (id.startsWith(idf.getPrefix())) {
+ return true;
+ } else {
+ return false;
+ }
+ }
else if (filter instanceof AnonIndividualFilter) {
return false;
}
@@ -0,0 +1,33 @@
+package org.monarchinitiative.owlsim.kb.filter;
+
+
+/**
+ * A filter that picks out individuals that with a particular prefix.
+ *
+ * If URIs are already mapped to CURIEs, use the prefix plus ':'
+ *
+ * If URIs are not mapped, use the full URI prefix
+ *
+ * @author cjm
+ *
+ */
+public class IdPrefixFilter implements Filter {
+
+ private String prefix;
+
+
+ public IdPrefixFilter(String prefix) {
+ super();
+ this.prefix = prefix;
+ }
+ public static IdPrefixFilter create(String prefix) {
+ return new IdPrefixFilter(prefix);
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+
+
+}
@@ -50,6 +50,9 @@ public void testFilterEngine() throws OWLOntologyCreationException, URISyntaxExc
//System.out.println(tf6);
//testFilter(tf6);
+ IdPrefixFilter pf = IdPrefixFilter.create("http://x.org/ia");
+ testFilter(pf, "http://x.org/ia", "http://x.org/iabc");
+
}
}