Commit Graph

3030 Commits (534ca2aff957a426bd7ac5aefb0891d715789c06)

Author SHA1 Message Date
Chris Rogers 534ca2aff9 All regressions in number parsing fixed.
This is in support of issues-1959.
2019-02-02 13:12:25 -05:00
Chris Rogers 6da1ec5c6e Fix regression in number parsing.
Fix regression that caused "X and one half" to parse as just X.

This is in support of issues-1959.
2019-02-01 23:24:45 -05:00
Chris Rogers f4eee8726a Refactor many methods in parse_en.
This improves the utility of the _ReplaceableNumber class, and updates
most of the number parsing functions to take tokens rather than text.
This simplifies the interactions between many of the functions, as there
is no need to convert back and forth between text and tokens.

This also adds some tests. Note that there are a few regressions that
will be fixed in a subsequent commit.
2019-02-01 23:04:54 -05:00
Chris Rogers 95aca10294 Fix _extract_decimal
Actually use the short_scale and ordinals values.
2019-02-01 18:57:28 -05:00
Chris Rogers 2ce632389f Fix and simplfy extract_numbers_en
This was calling convert_words_to_numbers and parsing out the resuling
numbers, which was a simple way of getting the numebrs in order, but it
choked on anything that didn't match the regex being used to parse
numbers, in particular numbers of the form '6e18'. The better solution
is to directly use extract_numbers_with_text (which now sorts by
start_index) and get the values from there directly.

This is in support of issues-1959.
2019-02-01 18:51:03 -05:00
Chris Rogers 6645ab6bfe Add short_scale and ordinal args to helpers.
This is in support of issues-1959.
2019-02-01 18:28:40 -05:00
Chris Rogers cbebf957e4 Add tests for extract_duration_en.
This is in support of issues-1959.
2019-02-01 18:22:46 -05:00
Chris Rogers 5c74789c2d Lower text before parsing.
This is in support of issues-1959.
2019-02-01 18:21:13 -05:00
Chris Rogers 23edb9eb00 Fix decimal/fraction parsing with leading numbers.
"Five hours seven and a half minutes" was parsing as 5.5. This is
resolved. Multiple fractions/decimals still cause problems, e.g.

convert_words_to_numbers("seven and a half and nine and a half")
Out[5]: '7 and a 0.5 and 9 and a 0.5'

This is in support of issues-1959.
2019-02-01 17:39:01 -05:00
Chris Rogers a3e94bcbc6 Add numbers, e.g. '20', '30' to sums
This is in support of issues-1959.
2019-01-30 22:53:22 -05:00
Chris Rogers 4732feab41 Fix indicies and substitution logic.
Placeholders are inserted into the text to maintain accurate
indicie relative to the original string.

This is in support of issues-1959.
2019-01-30 22:06:02 -05:00
Chris Rogers 49274493d9 Update convert_words_to_numbers logic.
The logic has been updated for start/end indexs.

This is in support of issues-1959.
2019-01-30 21:18:48 -05:00
Chris Rogers 03a445991c Fix multiplies and extract_numbers_with_text
A small bug caused things like "two hundred twenty" to return only the
"hundred tenty" for the text. This has been fixed.

extract_numbers_with_text was updated to deal with the new return types
of the functions it depends on. Specifically, it accounts for the start
and end index values.

This is in support of issues-1959.
2019-01-30 18:24:18 -05:00
Chris Rogers 71836b61ec Fix decimal and fraction parsing.
This updates the _extract_fraction and _extract_decimal functions to
handle the new token format.
2019-01-30 18:03:25 -05:00
Chris Rogers 48214ca66a Introduce tokens for number parsing.
Replace use of tuples with a dedicated class. This improves clarity by
giving named accessors.

This is in support of issues-1959.
2019-01-30 16:48:59 -05:00
Chris Rogers 9db9b6107b Change approach to number/text replacment.
Previously it was assumed that the orgiginal text would be enough to
determine where in a string a number should go, however, in some
scenarios, that does not work, and results in the wrong values being
parsed.

A different, and smarter approach is being taken now, in which the
original string is initially split into a list of tuples of
(index, word) where index is the index of the word within the string.
All subsequent processing is done on these tuples, meaning we always
know exactly where the words were in the orginal string. This should
make text replacement perfect, as we can always sub out the exact,
correct words, based on their indicies.

extract_number_with_text_en now returns the number parsed, the text that
represents the number, the start index, and the end index.

Things are not yet working perfectly. Here is roughly the current state
of the world:

from mycroft.util.lang.parse_en import *
extract_number_with_text_en("this is some two hundred thousand twenty
two hours")
Out[3]: (200022, 'hundred thousand twenty two', 4, 7)
extract_number_with_text_en("this is some twenty two hours")
Out[4]: (22, 'twenty two', 3, 4)
extract_number_with_text_en("this is some twenty hours")
Out[5]: (20, 'twenty', 3, 3)
extract_number_with_text_en("this is some two and a half hours")
Out[6]: (2, 'two', 3, 3)
extract_number_with_text_en("this is some two point five hours")
Out[7]: (2, 'two', 3, 3)

The list of tuples is a bit of a hassle to deal with. In a future
commite the will be replaced with dictionaries, or even better, Token
objects, that contain the word and it's index. This would make the
code easier to reason about (removing lots things like words[0][1]
which has no meaning without deep understanding of the code).

This is in support of issues-1959.
2019-01-29 22:33:23 -05:00
Chris Rogers 8a5bf49651 Handle lists of summation numbers.
Phrases like "twenty thirty forty" would return
(40, "twenty thrity forty"). This changes that so
(40 "forty") is returned.
2019-01-29 21:25:06 -05:00
Chris Rogers 690df0b1d3 Update entract_numbers_en to use the new functions.
This is in support of issues-1959.
2019-01-29 20:57:16 -05:00
Chris Rogers f4723b1026 Cleanup parse_en.
Rename some functions, and fix docs/pep8 issues.
2019-01-29 20:50:13 -05:00
Chris Rogers 31760e6c9c Fix existing extract_duration tests.
This is in support of issues-1959.
2019-01-29 20:31:31 -05:00
Chris Rogers 9aa02587b3 Fix an issue with extractnumber_en_with_text
Articles (a, an, the) that appeared immediately before the number were
included in the returned text. This fixes those issues.

The solution isn't super clean - it craetes a new function to wrap the
old one (unavoidable, since the articles can be needed for fractions),
and splits the returned string, the strips leading artivles.

Since strings are immutable, this is probably not super efficient. Might
be better to eventually use lists as much as possible, and only create a
string at the end (though the lists will come with their own problems,
so that could turn out to be a wash). In any case, this works for now.
2019-01-29 20:25:38 -05:00
Chris Rogers 0b8e88a325 Fix docs for _initialize_number_data.
This is in support of issues-1959.
2019-01-29 20:03:41 -05:00
Chris Rogers 9ff7fd5452 Fix issues with extractnumber_en_with_text
Issues fixed:
Lists, e.g. "some words one two three" would return (3, "one two three")
Negaitve words were not included in output, e.g. "negative five" would
return (-5, "five").

This is in support of issues-1959.
2019-01-29 19:53:30 -05:00
Chris Rogers b5ffbcc549 Fix edgecase in extractnumber_en_with_text
Any articles (a, an, the) appearing before the number would be included
in the text, e.g. "set a timer for eight minutes" returned:
(8, 'a eight')

This fix clears the number words list if no number words have been
found. Note that articles can't simple be filtered, as they are
often a part of the numebr (e.g. three and a half).

This is in support of issues-1959.
2019-01-28 17:28:27 -05:00
Chris Rogers 12e5fd603a Implement methods useful for extract_duration
Methods implemented include:

extract_number_with_text
extract_numbers_with_text
convert_words_to_numbers
extract_duration

This is in support of issues-1959. This continues the work of
returning the relevant text that corresponds to a number
parsed from a string.
2019-01-28 17:04:12 -05:00
Chris Rogers 5252e710b5 Prevent the conversion of ints to floats>
This is in support of issues-1959. This continues the work of
returning the relevant text that corresponds to a number
parsed from a string.
2019-01-26 18:06:11 -05:00
Chris Rogers 05046c7390 Add ordinal and fraction support.
This is in support of issues-1959. This continues the work of returning
the relevant text that corresponds to a number parsed from a string.
2019-01-26 17:39:56 -05:00
Chris Rogers 49c344c1d7 Return correct text for decimals and fractions
This is in support of issues-1959. This continues the work of returning
the relevant text that corresponds to a number parsed from a string.
2019-01-26 14:36:01 -05:00
Chris Rogers 5a3d809e68 Begin returning text with parsed numbers
This is in support of issues-1959. This begins the work of returning the
relevant text that corresponds to a number parsed from a string. Here's
a sample showing the basic functionality/state of the world (showing
some of the remaining cases to handle)

>>> from mycroft.util.lang.parse_en import *
>>> extractnumber_en_with_text("three hours twenty minutes")
(3, 'three')
>>> extractnumber_en_with_text("twenty minutes")
(20, 'twenty')
>>> extractnumber_en_with_text("twenty five minutes")
(25, 'twenty five')
>>> extractnumber_en_with_text("two hundred twenty five minutes")
(225, 'two hundred twenty five')
>>> extractnumber_en_with_text("three and a half minutes")
(3.5, 'three and a half minutes')
>>> extractnumber_en_with_text("three point five minutes")
(3.5, 'three point five minutes')

====  Tech Notes ====
Checks if the word being parsed is relevant to number parsing. If it is
not, and we have already found number words, we return what we have. If
it is, we add it to a list of words representing the current number
being parsed.

====  Documentation Notes ====
The old implementation of extractnumber_en seems to generally return the
last number in the text. This change will cause the first number to be
returned.
2019-01-26 14:26:00 -05:00
Chris Rogers 6d9447128b Cleanup unnecessary comments/improve docs.
This is part of a refactor of extractnumber_en, with the ultimate
goal of making it easier to maintain and extend (should also
improve perf).  This is in support of issues-1959.
2019-01-25 21:06:29 -05:00
Chris Rogers 8d588743d0 Extract fraction and decimal methods.
This is part of a refactor of extractnumber_en, with the ultimate
goal of making it easier to maintain and extend (should also
improve perf).  This is in support of issues-1959.

All tests (minus extract_duration, which has not yet been implemented)
are passing at this stage.
2019-01-25 21:02:34 -05:00
Chris Rogers 1a176da6b6 Deal with scale numbers and plurarls appropriately.
This is part of a refactor of extractnumber_en, with the ultimate
goal of making it easier to maintain and extend (should also
improve perf).  This is in support of issues-1959.

All tests (minus extract_duration, which has not yet been implemented)
are passing at this stage.
2019-01-25 20:44:59 -05:00
Chris Rogers a6aaaa365a Extract ordinals from extractnumber_en
This is part of a refactor of extractnumber_en, with the ultimate goal
of making it easier to maintain and extend (should also improve perf).
This is in support of issues-1959.
2019-01-23 22:04:02 -05:00
Chris Rogers 8f03f18219 Refactor extractnumber_en - extract constants
Begins a refactor of extractnumber_en, with the ultimate goal of making
it easier to maintain and extend (should also improve perf). This is
in support of issues-1959.
2019-01-23 21:36:56 -05:00
Chris Rogers 3a9f11c67e Add extract_duration skeleton 2019-01-23 18:25:22 -05:00
Åke 9ef95506d0 GUI update number 6 (#1964)
* Add communication from GUI to skills

- "set" events from Qt will set/update a variable in the skills .gui member
- It's possible to add general event handlers using self.gui.register_handler()
- Moved registration of skill_id to just after skill init

* Ensure that simultaneously writes doesn't occur

Wrap WebSocketHandler.write_message() with a lock in an attempt to handle "buffererror: existing exports of data: object cannot be re-sized."

* Add better logging to help debug disconnect issue

* Allow overriding the idle page

SkillGUI.show_page() and SkillGUI.show_pages() now takes an optional
override_idle parameter. This is used as a hint by the mark-2 skill
and if possible the idle screen will not be shown.

* Improve debugging using Logger

* Raise exception when sending a non-existing gui page

* Restore running state to new connections

When a GUI is connected data and running namespaces are synchronised and
shown.

This refactors the code quite a bit moving the GUI state from the GUIConnection
object to the Enclosure.

The GUIConnection object does the handles the sync in the on_connection_open()
method.

* Add gui.page_interaction message

Currently triggered on page change on the display.

* Handle message when gui changes sessionData

* Check if socket exists on gui before sending data

* Increase port on each failure and retry
2019-01-22 08:45:19 -06:00
Åke 1b0ff61609
Merge pull request #1966 from MycroftAI/bugfix/issues-1962
Bugfix/issues 1962
2019-01-22 08:23:26 +01:00
Chris Rogers 12a55c4cb8 Issues-1962 - Fix/add tests for normalize 2019-01-21 18:44:20 -05:00
Chris Rogers 644d75cfc9 Issues-1962 - Revert changes to normalize_en 2019-01-21 18:37:04 -05:00
Åke 7fd59bf488
Merge pull request #1958 from alistair23/alistair/utf8-encoding
dialog: Open template file as utf8 encoded
2019-01-18 10:36:23 +01:00
Alistair Francis 71afcb9ce5 text_client.py: Don't log stack trace on missing conf (#1957)
If we are missing the ".mycroft_cli.conf" file we print a message to the
user informing them that we are ignoring the missing file along with a stack trace. The stack trace is really not necessary so this removes it.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-18 09:59:55 +01:00
Alistair Francis 4c140c3cfe dialog: Open template file as utf8 encoded
To avoid UnicodeDecodeError's when opening files tell Python that we
want to open the file as a utf8 encoded file.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-17 11:45:14 -08:00
devs-mycroft ce37c7861b Version bump from 18.8.10 to 18.8.11 2019-01-17 14:46:19 +00:00
Åke 06f9d2f4db
Merge pull request #1956 from MycroftAI/feature/threaded-common-query
Run common query skill queries in threads
2019-01-17 12:38:12 +01:00
Åke Forslund d5f04ada76 Run queries in threads 2019-01-17 12:00:37 +01:00
Åke f98e569259
Merge pull request #1955 from MycroftAI/revert-threaded-emitter
Revert "Merge pull request #1889 from forslund/feature/threaded-emitter"
2019-01-17 11:54:09 +01:00
Åke Forslund f106f9603f Revert "Merge pull request #1889 from forslund/feature/threaded-emitter"
This reverts commit cb891ecf2f, reversing
changes made to 876b5393f7.
2019-01-17 11:11:43 +01:00
Åke 3c032734e5
Merge pull request #1954 from MycroftAI/bugfix/cli-ctrl-c
Fix Ctrl+C handling in CLI
2019-01-17 09:48:44 +01:00
Steve Penrod b38668a2ef Fix Ctrl+C handling in CLI
Ctrl+C was not being properly handled by the CLI, resulting in an  unclean
shutdown and other unexpected consequences -- e.g. a
"./start-mycroft.sh debug" would kill the background processes on exit.  The
KeyboardException was never being triggered.

Now the SIGINT is being captured and Ctrl+C behaves (as intended) just like
pressing Ctrl+X.
2019-01-17 09:47:43 +01:00
Matthew D. Scholefield cb891ecf2f
Merge pull request #1889 from forslund/feature/threaded-emitter
Run emitter using threadpool
2019-01-16 10:37:38 -06:00