Re: patch to make find more helpful

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: patch to make find more helpful

Nick Drummond
Alan,

The ' bug is now fixed.
Users can currently search for middle of string matches by adding a wildcard at the start of the search term.
I think it would clutter the results in many cases if the search automatically did this.
Searches that hit the URI, synonyms etc will be implemented soon (I hope).

Nick

On Fri, Jul 4, 2008 at 3:55 PM, Alan Ruttenberg <[hidden email]> wrote:
The current version has a bug in that the "'" at the start of a rendering isn't ignored in a find.
Also, I think it is useful to provide results for middle of string searches. It's rare that someone doesn't want to find those, though they would want the initial string matches first. Finally, ideally find would search a bunch of fields. As a start to that, this patch

1) Sticks to the current behavior if the string is leading or trailing "*" or regex searches have been been set in the preferences.
2) Otherwise adds, after the current results to find, mid-string searches and hits against the URI (something desirable for OBI now).
3) In the process fixes the "'" bug.

-Alan


svn diff /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java
Index: /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java
===================================================================
--- /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java (revision 10728)
+++ /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java (working copy)
@@ -56,6 +56,9 @@
            return Collections.emptySet();
        }
        Set<T> results = new HashSet<T>();
+       Set<T> looserResults = new HashSet<T>();
+       Set<T> URIResults = new HashSet<T>();
+       T entity;
        if (EntityFinderPreferences.getInstance().isUseRegularExpressions()) {
            try {
                Pattern pattern = Pattern.compile(match);
@@ -116,19 +119,33 @@
            if (logger.isDebugEnabled()) {
                logger.debug("Match: " + match);
            }
+
+           Pattern looserPattern = Pattern.compile("(?s)(?i)"+match.replaceAll("([\\\\*+?|{}\\[\\]()^$.])", "\\\\$1"));
+           Matcher looserM = looserPattern.matcher("");
+
            for (String rendering : getRenderings(type)) {
                int offset = 0;
+               entity = getEntity(rendering, type);
                if (rendering.length() > 0){
                    if (rendering.charAt(0) == '\'') {
                        offset = 1;
-                    }
+                    };
                    if (matcher.matches(rendering.toLowerCase(), match)) {
-                        results.add(getEntity(rendering, type));
+                        results.add(entity);
+                    };
+                   looserM.reset(rendering);
+                    if (looserM.find()) {
+                       looserResults.add(entity);
+                   }
+                   looserM.reset(entity.getURI().toString());
+                    if (looserM.find()) {
+                       URIResults.add(entity);
                    }
                }
            }
        }
-
+       results.addAll(looserResults);
+       results.addAll(URIResults);
        return results;
    }



_______________________________________________
p4-feedback mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/p4-feedback
Reply | Threaded
Open this post in threaded view
|

Re: patch to make find more helpful

Alan Ruttenberg-2

On Jul 14, 2008, at 11:43 AM, Nick Drummond wrote:

Alan,

The ' bug is now fixed.
Users can currently search for middle of string matches by adding a wildcard at the start of the search term.
I think it would clutter the results in many cases if the search automatically did this.
It wouldn't if the search results were ordered by the distance to the beginning of the string...
-Alan

Searches that hit the URI, synonyms etc will be implemented soon (I hope).

Nick

On Fri, Jul 4, 2008 at 3:55 PM, Alan Ruttenberg <[hidden email]> wrote:
The current version has a bug in that the "'" at the start of a rendering isn't ignored in a find.
Also, I think it is useful to provide results for middle of string searches. It's rare that someone doesn't want to find those, though they would want the initial string matches first. Finally, ideally find would search a bunch of fields. As a start to that, this patch

1) Sticks to the current behavior if the string is leading or trailing "*" or regex searches have been been set in the preferences.
2) Otherwise adds, after the current results to find, mid-string searches and hits against the URI (something desirable for OBI now).
3) In the process fixes the "'" bug.

-Alan


svn diff /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java
Index: /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java
===================================================================
--- /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java (revision 10728)
+++ /Users/alanr/repos/protege4/plugins/org.protege.editor.owl/src/org/protege/editor/owl/model/find/EntityFinderImpl.java (working copy)
@@ -56,6 +56,9 @@
            return Collections.emptySet();
        }
        Set<T> results = new HashSet<T>();
+       Set<T> looserResults = new HashSet<T>();
+       Set<T> URIResults = new HashSet<T>();
+       T entity;
        if (EntityFinderPreferences.getInstance().isUseRegularExpressions()) {
            try {
                Pattern pattern = Pattern.compile(match);
@@ -116,19 +119,33 @@
            if (logger.isDebugEnabled()) {
                logger.debug("Match: " + match);
            }
+
+           Pattern looserPattern = Pattern.compile("(?s)(?i)"+match.replaceAll("([\\\\*+?|{}\\[\\]()^$.])", "\\\\$1"));
+           Matcher looserM = looserPattern.matcher("");
+
            for (String rendering : getRenderings(type)) {
                int offset = 0;
+               entity = getEntity(rendering, type);
                if (rendering.length() > 0){
                    if (rendering.charAt(0) == '\'') {
                        offset = 1;
-                    }
+                    };
                    if (matcher.matches(rendering.toLowerCase(), match)) {
-                        results.add(getEntity(rendering, type));
+                        results.add(entity);
+                    };
+                   looserM.reset(rendering);
+                    if (looserM.find()) {
+                       looserResults.add(entity);
+                   }
+                   looserM.reset(entity.getURI().toString());
+                    if (looserM.find()) {
+                       URIResults.add(entity);
                    }
                }
            }
        }
-
+       results.addAll(looserResults);
+       results.addAll(URIResults);
        return results;
    }


_______________________________________________
p4-feedback mailing list


_______________________________________________
p4-feedback mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/p4-feedback