old-parser: Commands without args are no longer suggested for multi-word input.

This commit is contained in:
satyr 2009-10-25 13:33:48 +09:00
Родитель 88eff41649
Коммит 2d2b681707
2 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -41,9 +41,6 @@ var EnParser = {
parseSentence: parseSentence,
};
Components.utils.import("resource://ubiquity/modules/utils.js");
var {isEmpty} = Utils;
var {push} = Array.prototype;
function shallowCopy(dic) {
@ -94,21 +91,24 @@ function parseSentence(inputString, verbList, makePPS) {
var words = [word for each (word in inputString.split(" ")) if (word)];
if (!words.length) return parsings;
var inputs = (words.length === 1
var verbOnly = words.length === 1;
var inputs = (verbOnly
? [[words[0], null, 1]]
: [[words[0], words.slice(1), 1], [words.pop(), words, .1]]);
for each (let verb in verbList) if (!verb.disabled)
for each (let verb in verbList) if ((verbOnly || verb.argCount) &&
!verb.disabled)
VERB: for each (let input in inputs) {
let matchScore = verb.match(input[0]);
if (!matchScore) continue;
let [, inputArgs, weight] = input, {args} = verb;
let [, inputArgs, weight] = input;
matchScore *= weight;
if (!inputArgs || isEmpty(args)) {
if (!inputArgs) {
parsings.push(makePPS(verb, {}, matchScore));
break VERB;
}
let preps = {}; // {source: "to", goal: "from", ...}
let {args} = verb, preps = {}; // {source: "to", goal: "from", ...}
for (let arg in args) preps[arg] = args[arg].preposition;
delete preps.object;
let hasObj = "object" in args;

Просмотреть файл

@ -698,7 +698,7 @@ function Verb(cmd, roleMap) {
// Use the presence or absence of the "arguments" dictionary
// to decide whether this is a version 1 or version 2 command.
if (this.newAPI) {
// New-style API: command defines arguments dictionary
// New-style API: command defines arguments array
// if there are arguments, copy them over using
// a (semi-arbitrary) choice of preposition
for each (let arg in cmd.arguments) {
@ -718,7 +718,7 @@ function Verb(cmd, roleMap) {
// Command defines DOType/DOLabel and modifiers dictionary.
// Convert this to argument dictionary.
// cmd.DOType must be a NounType, if provided.
if (cmd.DOType) {
if ("DOType" in cmd) {
args.object = {
type: cmd.DOType,
label: cmd.DOLabel,
@ -744,6 +744,7 @@ function Verb(cmd, roleMap) {
}
}
}
this.argCount = [0 for (_ in args)].length;
}
Verb.prototype = {
get name V_name() this.cmd.names[0],