mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Keep panels, compound names and signed coordinates apart when reading a line
- "hide flights near Left Bank, Paris" closed the left panel: a side is closed only when the clause names nothing but the side. - "flights near Trinidad and Tobago" looked up Trinidad alone, and "take me to New York City NY" nothing (the command's words counted against the name): the whole place is looked up, and the limit counts its words. - "flights near 30.27, +97.74" and "30.27; -97.74" were split at the sign or semicolon; both stay coordinates. - "hide flights, show ships" listed "No layers are on": several requests in a line are read as one plan, as with "and". Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
8dae95e4da
commit
36264005a8
3 files changed
+64
-8
No files matched your search
@@ -109,9 +109,10 @@ function panelStep(clause) {
|
||||
(/\beverything\b/.test(clause) && onlyNames(clause, /\beverything\b/))
|
||||
)
|
||||
return { kind: 'panel', action: 'close', side: 'all' };
|
||||
if (/\bleft\b/.test(clause))
|
||||
// "hide the left panel", never "hide flights near Left Bank".
|
||||
if (/\bleft\b/.test(clause) && onlyNames(clause, /\b(left|side)\b/g))
|
||||
return { kind: 'panel', action: 'close', side: 'left' };
|
||||
if (/\bright\b/.test(clause))
|
||||
if (/\bright\b/.test(clause) && onlyNames(clause, /\b(right|side)\b/g))
|
||||
return { kind: 'panel', action: 'close', side: 'right' };
|
||||
for (const [pattern, side, item, name] of PANEL_NAMES)
|
||||
if (pattern.test(clause) && /panel/.test(clause))
|
||||
@@ -359,7 +360,7 @@ const GO_TAIL =
|
||||
|
||||
/** Clause separators; "black and white" is joined first so it survives. */
|
||||
const SEPARATORS =
|
||||
/(\s*(?:,|;|\+|&|\band then\b|\bthen\b|\band\b|\balso\b)\s*)/;
|
||||
/(\s*(?:,|;(?!\s*[-+]?\d)|\+(?!\d)|&|\band then\b|\bthen\b|\band\b|\balso\b)\s*)/;
|
||||
|
||||
function tidy(text) {
|
||||
return text.replace(/\s+/g, ' ').trim();
|
||||
|
||||
+14
-5
@@ -932,7 +932,8 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
!switching ||
|
||||
isPanelText(line) ||
|
||||
isWholeMapClear(line) ||
|
||||
/\b(near|in|at|over|around|and|then)\b/.test(switching[2] || '')
|
||||
// More than one request ("hide flights, show ships") is the parser's.
|
||||
/\b(near|in|at|over|around|and|then)\b|[,;+&]/.test(switching[2] || '')
|
||||
)
|
||||
return null;
|
||||
const verb = switching[1];
|
||||
@@ -1517,8 +1518,7 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
if (line.length < minPlaceChars(line) || line.startsWith('>')) return null;
|
||||
if (/^[0-9a-f]{6}$/i.test(line) || CALLSIGN.test(line.replace(/\s+/g, '')))
|
||||
return null;
|
||||
if (line.includes('?') || line.split(/\s+/).length > placeWordLimit(line))
|
||||
return null;
|
||||
if (line.includes('?')) return null;
|
||||
if (VILLAGES.test(line) || exactCommand(line) || coordinateTarget(line))
|
||||
return null;
|
||||
if (switchRows(line, askRow(text))) return null;
|
||||
@@ -1531,13 +1531,22 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
if (place && !/[\p{L}\p{N}]/u.test(place.place)) return null;
|
||||
// A line of commands with no place in it ("night vision", "zoom in").
|
||||
if (parsed.steps.length && !place) return null;
|
||||
const words = (value) => value.split(/\s+/).length;
|
||||
// The words the place has, not the command around it ("take me to New
|
||||
// York City NY"); a line that may be one name counts all of its words.
|
||||
const named = place && !parsed.ambiguous ? place.place : line;
|
||||
if (words(named) > placeWordLimit(named)) return null;
|
||||
// "flights near Trinidad and Tobago": the whole name is looked up; the
|
||||
// rows still offer each part ("Tokyo and Osaka").
|
||||
const joined = (value) =>
|
||||
[value, ...(parsed.extraPlaces || [])].join(' and ');
|
||||
// After "go to … , noir" the place read is the one to look up.
|
||||
if (parsed.peeled && place) return place.place;
|
||||
if (parsed.peeled && place) return joined(place.place);
|
||||
return parsed.ambiguous || !place
|
||||
? text
|
||||
: place.place === line
|
||||
? text
|
||||
: place.place;
|
||||
: joined(place.place);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -601,3 +601,49 @@ test('only a layer in or near a place is counted, never a name', () => {
|
||||
])
|
||||
assert.equal(omnibar.countRequest(text), null, text);
|
||||
});
|
||||
|
||||
test('a place named Left or Right is no panel to close', () => {
|
||||
const omnibar = createOmnibar({ layers: layers(['flights']) });
|
||||
const { rows, defaultIndex } = omnibar.rows(
|
||||
'hide flights near Left Bank, Paris',
|
||||
);
|
||||
assert.equal(rows[defaultIndex].kind, 'plan');
|
||||
assert.ok(rows[defaultIndex].steps.every((step) => step.kind !== 'panel'));
|
||||
for (const text of ['hide the left panel', 'close right side']) {
|
||||
const read = omnibar.rows(text);
|
||||
assert.ok(
|
||||
read.rows[read.defaultIndex].steps.some((step) => step.kind === 'panel'),
|
||||
text,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the place service gets the whole place, however it is asked', () => {
|
||||
const omnibar = createOmnibar({ layers: layers() });
|
||||
assert.equal(
|
||||
omnibar.placeQuery('flights near Trinidad and Tobago'),
|
||||
'trinidad and tobago',
|
||||
);
|
||||
assert.equal(
|
||||
omnibar.placeQuery('take me to New York City NY'),
|
||||
'New York City NY',
|
||||
);
|
||||
// A signed longitude or a semicolon stays inside the coordinates.
|
||||
for (const text of [
|
||||
'show flights near 30.27, +97.74',
|
||||
'go to 30.27; -97.74',
|
||||
]) {
|
||||
const { rows, defaultIndex } = omnibar.rows(text);
|
||||
assert.ok(defaultIndex >= 0, text);
|
||||
assert.equal(omnibar.placeQuery(text), null, text);
|
||||
assert.notEqual(rows[defaultIndex].kind, 'none', text);
|
||||
}
|
||||
});
|
||||
|
||||
test('several switches in one line are one plan', () => {
|
||||
const omnibar = createOmnibar({ layers: layers(['flights']) });
|
||||
for (const text of ['hide flights, show radio', 'hide flights; show radio']) {
|
||||
const { rows, defaultIndex } = omnibar.rows(text);
|
||||
assert.equal(rows[defaultIndex].kind, 'plan', text);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user