Comments (5)
Another thing we could do is within State::step()
record each (src, trg)
pair for the main symbol and then skip any alt step that would be between the same pair. (Though we'd probably want to check whether that noticeably slowed anything down.)
from lttoolbox.
Each time you step by an uppercase letter, it also steps by the lowercase version, so for an N-letter word, you have 2^N states when you reach the end.
from lttoolbox.
Oh the reason we only see one result is that if it's not dictionaryCase
, we apply input casing to each result, and they're merged into one.
$ echo BADGER | lt-proc --dictionary-case a.bin
^BADGER/baDGER<guess>/bADGEr<guess>/bADGeR<guess>/bADGer<guess>/bADgER<guess>/bADgEr<guess>/bADgeR<guess>/bADger<guess>/bAdGER<guess>/bAdGEr<guess>/bAdGeR<guess>/bAdGer<guess>/bAdgER<guess>/bAdgEr<guess>/bAdgeR<guess>/bAdger<guess>/bADGER<guess>/baDGEr<guess>/baDGeR<guess>/baDGer<guess>/baDgER<guess>/baDgEr<guess>/baDgeR<guess>/baDger<guess>/badGER<guess>/badGEr<guess>/badGeR<guess>/badGer<guess>/badgER<guess>/badgEr<guess>/badgeR<guess>/badger<guess>/BaDGER<guess>/BADGEr<guess>/BADGeR<guess>/BADGer<guess>/BADgER<guess>/BADgEr<guess>/BADgeR<guess>/BADger<guess>/BAdGER<guess>/BAdGEr<guess>/BAdGeR<guess>/BAdGer<guess>/BAdgER<guess>/BAdgEr<guess>/BAdgeR<guess>/BAdger<guess>/BADGER<guess>/BaDGEr<guess>/BaDGeR<guess>/BaDGer<guess>/BaDgER<guess>/BaDgEr<guess>/BaDgeR<guess>/BaDger<guess>/BadGER<guess>/BadGEr<guess>/BadGeR<guess>/BadGer<guess>/BadgER<guess>/BadgEr<guess>/BadgeR<guess>/Badger<guess>$
I feel like it should be possible to do some filtering earlier. We're looping back to the same FST-node over and over again:
but fst_processor doesn't just keep track of the Node, but also the sequence leading up to it:
struct TNodeState
{
Node *where;
std::vector<std::pair<int, double>> *sequence;
// a state is "dirty" if it was introduced at runtime (case variants, etc.)
bool dirty;
Would it be possible to filter out ones where the node is the same and the last part of the sequence differs?
Alternatively when doing step/apply, could we check if the result is the same, and never use the tolower(val)
(alt
) if they end up in the same Node? It wouldn't be a general solution, but would help in the common case of a-zA-Z.
from lttoolbox.
Another option, which I think we should do regardless (to prevent me from DoS-ing our servers with bad regexes), is have a max state size. As soon as you go over about 2^16 states you can feel the slowdown for a single (long, uppercase) word (and you're bound to be getting so many results it's mostly garbage), so perhaps simply
diff --git a/lttoolbox/fst_processor.cc b/lttoolbox/fst_processor.cc
index 1466ffb..98caea7 100644
--- a/lttoolbox/fst_processor.cc
+++ b/lttoolbox/fst_processor.cc
@@ -1087,7 +1087,7 @@ FSTProcessor::analysis(InputFile& input, UFILE *output)
}
else
{
- current_state.step_case(val, caseSensitive);
+ current_state.step_case(val, caseSensitive || current_state.size() >= 65536);
}
if(current_state.size() != 0)
@@ -2277,7 +2277,7 @@ FSTProcessor::bilingual(InputFile& input, UFILE *output, GenerationMode mode)
}
if(current_state.size() != 0)
{
- current_state.step_case(val, caseSensitive);
+ current_state.step_case(val, caseSensitive || current_state.size() >= 65536);
}
if(current_state.isFinal(all_finals))
{
Maybe with a warning the first time we reach that size.
from lttoolbox.
when doing step/apply, could we check if the result is the same, and never use the tolower(val) (alt) if they end up in the same Node?
@ftyers can you imagine anywhere we would want a lowercase character (on the output-side) if input was upper and upper is possible and we end up in the same FST node? (That'd be like if you had both "iphone" and "iPhone" in your dix and user wrote "iPhone" – analysis would now only give "iPhone" instead of both. I would see that as a good thing, but maybe there are use-cases for having both.)
from lttoolbox.
Related Issues (20)
- utfcpp HOT 1
- Python module undefined symbol
- auto-section big fst's for faster compilation HOT 2
- Duplication in generation HOT 13
- compounding on multiwords
- soft hyphens not always ignored
- configure fails because of missing utf8.h HOT 4
- postgenerator nests wordblanks HOT 1
- `<t/>` alignment in `lsx-comp`
- lsx-comp --debug HOT 2
- lt-proc loops on non-alpha followed by 2-unit codepoint HOT 2
- Post-generation problems when uppercase
- lt-trim trims valid analyses HOT 4
- Transliteration mode doubling inserted characters sometimes
- possible optional input format for lt-comp: lt-expanded dictionaries
- Expand (some) ICU character classes in regex_compiler? HOT 3
- Option to set compound_max_elements in lt-proc HOT 1
- Support for `ANY_CHAR` in regular dix files? HOT 1
- lt-proc -g -b no longer works
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lttoolbox.