Created
June 12, 2011 16:07
-
-
Save kiwanami/1021707 to your computer and use it in GitHub Desktop.
GNOME Do 0.8.3.1 のmigemo化パッチ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- gnome-do-0.8.3.1+dfsg/Do.Platform/Makefile.am 2009-06-29 09:19:29.000000000 +0900 | |
+++ mod/Do.Platform/Makefile.am 2011-06-13 00:04:42.010788898 +0900 | |
@@ -52,6 +52,7 @@ | |
src/Do.Platform/Services.cs \ | |
src/Do.Platform/INetworkService.cs \ | |
src/Do.Platform/NetworkStateChangedEventArgs.cs \ | |
+ src/Do.Platform/Migemo.cs \ | |
src/Do.Universe/Do.Universe.Common/EmailAction.cs \ | |
src/Do.Universe/Do.Universe.Common/OpenAction.cs \ | |
src/Do.Universe/Do.Universe.Common/OpenUrlAction.cs \ | |
--- gnome-do-0.8.3.1+dfsg/Do/src/Do.Core/RelevanceProvider.cs 2009-06-29 09:19:29.000000000 +0900 | |
+++ mod/Do/src/Do.Core/RelevanceProvider.cs 2011-06-13 00:03:09.845027893 +0900 | |
@@ -23,6 +23,7 @@ | |
using System.Collections.Generic; | |
using System.Runtime.Serialization; | |
using System.Runtime.Serialization.Formatters.Binary; | |
+using System.Text.RegularExpressions; | |
using Do.Platform; | |
using Do.Universe; | |
@@ -120,6 +121,9 @@ | |
float score; | |
string ls = s.ToLower (); | |
+ score = tryMigemoMatch(s,query); | |
+ if (score > 0) return score; | |
+ | |
//Find the shortest possible substring that matches the query | |
//and get the ration of their lengths for a base score | |
int[] match = findBestSubstringMatchIndices (ls, query); | |
@@ -169,6 +173,30 @@ | |
return score; | |
} | |
+ private static KaoriYa.Migemo.Migemo migemo = new KaoriYa.Migemo.Migemo("/usr/local/share/migemo/utf-8/migemo-dict"); | |
+ private static string migemoLastQuery; | |
+ private static string migemoLastRegex; | |
+ | |
+ protected static float tryMigemoMatch(string s, string query) | |
+ { | |
+ if (query.Length < 3) | |
+ return 0f; | |
+ | |
+ if (migemoLastQuery != query) { | |
+ migemoLastQuery = query; | |
+ migemoLastRegex = migemo.Query(query); | |
+ } | |
+ if (migemoLastRegex == null) | |
+ return 0f; | |
+ | |
+ Match match = Regex.Match(s, migemoLastRegex); | |
+ //Console.WriteLine("IN:["+query+"] -> ["+rx+"] > FOR ["+s+"] MATCH ["+match+"]"); | |
+ if (match.Value == "") | |
+ return 0f; | |
+ | |
+ return 0.9f + (float)(0.1f * match.Value.Length / s.Length); | |
+ } | |
+ | |
/// <summary> | |
/// Finds the shortest substring of s that contains all the characters of query in order | |
/// </summary> | |
--- gnome-do-0.8.3.1+dfsg/Do.Platform/src/Do.Platform/Migemo.cs 2011-06-23 12:08:00.865256923 +0900 | |
+++ mod/Do.Platform/src/Do.Platform/Migemo.cs 2011-06-12 23:32:24.310273542 +0900 | |
@@ -33,27 +33,27 @@ | |
#endregion | |
#endregion | |
-#region Link to migemo.dll | |
- [DllImport("migemo.dll")] | |
+#region Link to libmigemo.so | |
+ [DllImport("libmigemo")] | |
private static extern IntPtr migemo_open(string dict); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern void migemo_close(IntPtr obj); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern IntPtr migemo_query(IntPtr obj, string query); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern void migemo_release(IntPtr obj, IntPtr result); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern int migemo_set_operator(IntPtr obj, | |
OperatorIndex index, string op); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern IntPtr migemo_get_operator(IntPtr obj, | |
OperatorIndex index); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern DictionaryId migemo_load(IntPtr obj, | |
DictionaryId id, string file); | |
- [DllImport("migemo.dll")] | |
+ [DllImport("libmigemo")] | |
private static extern int migemo_is_enable(IntPtr obj); | |
#endregion | |
@@ -160,7 +160,7 @@ | |
#region Test entrypoint | |
#if TEST_MIGEMO | |
- // テスト関数 | |
+ // ー | |
public static int Main(string[] args) | |
{ | |
Migemo m; | |
--- gnome-do-0.8.3.1+dfsg/Do.Interface.Linux/src/Do.Interface/Util.cs 2009-06-29 09:19:29.000000000 +0900 | |
+++ mod/Do.Interface.Linux/src/Do.Interface/Util.cs 2011-06-23 12:07:50.144009168 +0900 | |
@@ -20,6 +20,7 @@ | |
using System; | |
using System.Collections.Generic; | |
+using System.Text.RegularExpressions; | |
using Gdk; | |
using Cairo; | |
@@ -36,8 +37,35 @@ | |
public static class Util | |
{ | |
+ | |
+ private static KaoriYa.Migemo.Migemo migemo = new KaoriYa.Migemo.Migemo("/usr/local/share/migemo/utf-8/migemo-dict"); | |
+ | |
public static string FormatCommonSubstrings (string main, string other, string format) | |
{ | |
+ // try migemo | |
+ try { | |
+ if (other.Length >= 3) { | |
+ string rx = migemo.Query(other); | |
+ if (rx != null) { | |
+ Match match = Regex.Match(main, rx); | |
+ if (match.Value != "") { | |
+ string skipped = main.Substring (0, match.Index); | |
+ string matched = match.Value; | |
+ string remainder = main.Substring(match.Index + match.Length); | |
+ return string.Format ("{0}{1}{2}", skipped, | |
+ string.Format(format, matched), | |
+ remainder); | |
+ } | |
+ } | |
+ } | |
+ } catch (System.ArgumentException e) { | |
+ //do nothing | |
+ } | |
+ return FormatCommonSubstrings_rec(main,other,format); | |
+ } | |
+ | |
+ private static string FormatCommonSubstrings_rec (string main, string other, string format) | |
+ { | |
int pos, len, match_pos, last_main_cut; | |
string lower_main, result; | |
string skipped, matched, remainder; | |
@@ -69,7 +97,7 @@ | |
skipped = main.Substring (last_main_cut, match_pos - last_main_cut); | |
matched = main.Substring (match_pos, len); | |
if ( skipped.Length + matched.Length < main.Length) { | |
- remainder = FormatCommonSubstrings ( main.Substring (match_pos + len), other.Substring (pos + len), format); | |
+ remainder = FormatCommonSubstrings_rec ( main.Substring (match_pos + len), other.Substring (pos + len), format); | |
} | |
else { | |
remainder = ""; | |
@@ -80,7 +108,7 @@ | |
} | |
if (result == "") { | |
// no matches | |
- result = main; | |
+ result = main; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment