diff --git a/atom.png b/atom.png new file mode 100644 index 0000000..de78cbe Binary files /dev/null and b/atom.png differ diff --git a/bak/Query.php b/bak/Query.php new file mode 100644 index 0000000..f00e29f --- /dev/null +++ b/bak/Query.php @@ -0,0 +1,69 @@ +term = $term; + } + + public function multiScore(array $words) { + $max = 0; + foreach ($words as $word) { + $max = max($max, $this->score($word)); + } + return $max; + } + + public function score($string) { + preg_match($this->regex(), $string, $matches); + $matched_chars = array_slice(array_values(array_filter($matches, 'strlen')), 2); + if (empty($matches)) return; + // How many characters you matched from the term + $positive_score = strlen(implode('', $matched_chars)) / strlen($this->term); + // Deductions for longer strings + $negative_score = abs(strlen($matches[1]) - strlen($this->term)) / 100; + return $positive_score - $negative_score; + } + + public function regex() { + if (!$this->regex) { + $this->regex = '/.*?(('; + $this->regex .= implode(')).*?|.*?((', array_map(function($gram) { + $gram_chars = str_split($gram); + return implode(').*?(', array_map(function($gram_char) { + return preg_quote($gram_char); + }, $gram_chars)); + }, $this->grams())); + $this->regex .= ')).*?/i'; + } + return $this->regex; + } + + public function grams() { + $max = strlen($this->term); + $min = ceil($this->accuracy * $max); + $grams = array(); + foreach (range($max, $min) as $length) { + $grams = array_merge($grams, $this->gramsByLength($length)); + } + return $grams; + } + + public function gramsByLength($length) { + $ngrams = array(); + $stop = strlen($this->term) - $length; + foreach (range(0, $stop) as $pos) { + $ngrams[] = substr($this->term, $pos, $length); + } + return $ngrams; + } + +} \ No newline at end of file diff --git a/info.plist b/info.plist index 0e63aa6..2f00862 100644 --- a/info.plist +++ b/info.plist @@ -6,8 +6,47 @@ connections + 055ECEC4-B7F5-4100-8CDE-A023FF61A467 + + + destinationuid + 2E4D25EE-2CC9-4E3F-BC71-A6A7D83A7357 + modifiers + 0 + modifiersubtext + + vitoclose + + + 2E4D25EE-2CC9-4E3F-BC71-A6A7D83A7357 + C1563D58-8291-4E0F-A111-35D965760584 + + + destinationuid + 2E4D25EE-2CC9-4E3F-BC71-A6A7D83A7357 + modifiers + 0 + modifiersubtext + + vitoclose + + + + ED8263F6-7B34-41EF-9127-43C32B9F1243 + + + destinationuid + 2E4D25EE-2CC9-4E3F-BC71-A6A7D83A7357 + modifiers + 0 + modifiersubtext + + vitoclose + + + FA97111C-147E-495D-8A96-BB0E6F708500 @@ -100,11 +139,153 @@ version 2 + + config + + alfredfiltersresults + + argumenttrimmode + 0 + argumenttype + 0 + escaping + 127 + keyword + atom + queuedelaycustom + 1 + queuedelayimmediatelyinitially + + queuedelaymode + 0 + queuemode + 1 + runningsubtext + + script + PROFILE="atom;~/.atom/projects.cson" CURRENT_FOLDER=`osascript src/get_current_folder.applescript` EDITOR="atom" php src/index.php {query} + scriptargtype + 0 + scriptfile + + subtext + + title + open project in atom + type + 0 + withspace + + + type + alfred.workflow.input.scriptfilter + uid + ED8263F6-7B34-41EF-9127-43C32B9F1243 + version + 2 + + + config + + alfredfiltersresults + + argumenttrimmode + 0 + argumenttype + 0 + escaping + 127 + keyword + vscode + queuedelaycustom + 1 + queuedelayimmediatelyinitially + + queuedelaymode + 0 + queuemode + 1 + runningsubtext + + script + PROFILE="vscode;~/Library/Application Support/Code/User/projects.json" CURRENT_FOLDER=`osascript src/get_current_folder.applescript` EDITOR="vscode" php src/index.php {query} + scriptargtype + 0 + scriptfile + + subtext + + title + open project in vscode + type + 0 + withspace + + + type + alfred.workflow.input.scriptfilter + uid + C1563D58-8291-4E0F-A111-35D965760584 + version + 2 + + + config + + alfredfiltersresults + + argumenttrimmode + 0 + argumenttype + 0 + escaping + 127 + keyword + code + queuedelaycustom + 1 + queuedelayimmediatelyinitially + + queuedelaymode + 0 + queuemode + 1 + runningsubtext + + script + PROFILE="vscode;~/Library/Application Support/Code/User/projects.json" CURRENT_FOLDER=`osascript src/get_current_folder.applescript` EDITOR="vscode" php src/index.php {query} + scriptargtype + 0 + scriptfile + + subtext + + title + open project in vscode + type + 0 + withspace + + + type + alfred.workflow.input.scriptfilter + uid + 055ECEC4-B7F5-4100-8CDE-A023FF61A467 + version + 2 + readme uidata + 055ECEC4-B7F5-4100-8CDE-A023FF61A467 + + xpos + 240 + ypos + 580 + 2E4D25EE-2CC9-4E3F-BC71-A6A7D83A7357 xpos @@ -112,6 +293,20 @@ ypos 120 + C1563D58-8291-4E0F-A111-35D965760584 + + xpos + 240 + ypos + 430 + + ED8263F6-7B34-41EF-9127-43C32B9F1243 + + xpos + 230 + ypos + 280 + FA97111C-147E-495D-8A96-BB0E6F708500 xpos diff --git a/media/vscode.png b/media/vscode.png index da48dd3..e9433d4 100644 Binary files a/media/vscode.png and b/media/vscode.png differ diff --git a/src/node/Query.php b/src/node/Query.php index f00e29f..a937402 100644 --- a/src/node/Query.php +++ b/src/node/Query.php @@ -3,67 +3,8 @@ namespace alfmarks; class Query { - - public $term; - - public $regex; - - public $accuracy = 0.5; - - public function __construct($term) { - $this->term = $term; - } - - public function multiScore(array $words) { - $max = 0; - foreach ($words as $word) { - $max = max($max, $this->score($word)); - } - return $max; - } - - public function score($string) { - preg_match($this->regex(), $string, $matches); - $matched_chars = array_slice(array_values(array_filter($matches, 'strlen')), 2); - if (empty($matches)) return; - // How many characters you matched from the term - $positive_score = strlen(implode('', $matched_chars)) / strlen($this->term); - // Deductions for longer strings - $negative_score = abs(strlen($matches[1]) - strlen($this->term)) / 100; - return $positive_score - $negative_score; + static function get_score($term, $string) { + foreach() } - - public function regex() { - if (!$this->regex) { - $this->regex = '/.*?(('; - $this->regex .= implode(')).*?|.*?((', array_map(function($gram) { - $gram_chars = str_split($gram); - return implode(').*?(', array_map(function($gram_char) { - return preg_quote($gram_char); - }, $gram_chars)); - }, $this->grams())); - $this->regex .= ')).*?/i'; - } - return $this->regex; - } - - public function grams() { - $max = strlen($this->term); - $min = ceil($this->accuracy * $max); - $grams = array(); - foreach (range($max, $min) as $length) { - $grams = array_merge($grams, $this->gramsByLength($length)); - } - return $grams; - } - - public function gramsByLength($length) { - $ngrams = array(); - $stop = strlen($this->term) - $length; - foreach (range(0, $stop) as $pos) { - $ngrams[] = substr($this->term, $pos, $length); - } - return $ngrams; - } - -} \ No newline at end of file +} + \ No newline at end of file diff --git a/vscode.png b/vscode.png new file mode 100644 index 0000000..e9433d4 Binary files /dev/null and b/vscode.png differ