2013-07-16 19 views
0

假設我有一些文本(代碼):給出一段文本,一些keyshorts和目標文本,如何獲得最小按鍵來轉換文本?

def text = ParamMenuable.this.linkText 
    def locPath: List[LocPath] = ParamMenuable.this.path 
    def parser = ParamMenuable.this.parser 
    def listToFrom(in: List[String]): Box[String] = in.headOption 

和一些keyshorts:

arrow-left/right/up/down: move cursor to left/right/up/down for one char 

ctrl + d: duplicate current line 
ctrl + arrow-left/right/up/down: move cursor to left/right/up/down for one word 
ctrl + y: delete current line 
... all kinds of key shorts you usually used 

與譯文是:

def text() = { 
    ParamMenuable.this.linkText 
    } 
    def locPath: List[LocPath] = ParamMenuable.this.path 
    def locPath22222: List[LocPath] = ParamMenuable.this.path 
    private def parser = { 
     return ParamMenuable.this.parser; 
    } 

我的問題是:有多少關鍵短褲你應該至少按下將源文本轉換爲目標文件?你可以選擇合適的關鍵短褲來做得更好。

+0

滑稽,它是某種[漢明距離]的擴展延長(http://en.wikipedia.org/wiki/Hamming_distance)與由熱鍵可到達的宏。這將取決於通過熱鍵可達到的轉換。然後,你必須嘗試列出它們(複製/粘貼是一個他們,但其他人?)。 – perror

+1

聽起來像是一個搜索問題。我會執行一個A * - 搜索來找到一個最佳的解決方案。 – MrSmith42

+1

我什麼也沒試,因爲我現在不知道做什麼:( – Freewind

回答

2

這可能是NP難。 This paper爲編輯器提供了硬度證明,其中插入,刪除和子串移動都具有不變的成本。該接近

%0 Book Section 
%D 2002 
%@ 978-3-540-43862-5 
%B Combinatorial Pattern Matching 
%V 2373 
%S Lecture Notes in Computer Science 
%E Apostolico, Alberto 
%E Takeda, Masayuki 
%R 10.1007/3-540-45452-7_9 
%T Edit Distance with Move Operations 
%U http://dx.doi.org/10.1007/3-540-45452-7_9 
%I Springer Berlin Heidelberg 
%8 2002-01-01 
%A Shapira, Dana 
%A Storer, JamesA. 
%P 85-98 
%G English 
0

東西將是http://en.wikipedia.org/wiki/Levenshtein_distance

儘管如此,它適用於只,而不是充滿了文字2-d區字符串。

然而,下面列出的是可能的:

possible 
postibla 

這裏,Levenshtein距離應爲2(因爲2個字符必須改變,以轉「可能」到「postibla」),但它也應該是可以打印的一個必須執行做變化的變化的跟蹤,如:

change 's' on position 4 to 't' 
change 'e' on position 8 to 'a' 

,進而,改變成一系列光標移動等的這樣(假設光標是在最左邊開頭):

-> -> -> DEL 't' -> -> -> DEL $ 'a' 

(這裏,符號$表達的事實光標在該行的末尾。) 然後,我們可以將優化規則,如:

(->)+$  => END 
(->)+DEL$ => END BS 

等。

只是想法....

相關問題