mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-21 10:49:33 -06:00
added pgf_lookup_word_prefix which makes it possible to do simple word prediction
This commit is contained in:
@@ -2581,6 +2581,7 @@ pgf_lookup_morpho(PgfConcr *concr, GuString sentence,
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
GuEnum en;
|
GuEnum en;
|
||||||
PgfSequences* sequences;
|
PgfSequences* sequences;
|
||||||
|
GuString prefix;
|
||||||
size_t seq_idx;
|
size_t seq_idx;
|
||||||
} PgfFullFormState;
|
} PgfFullFormState;
|
||||||
|
|
||||||
@@ -2600,6 +2601,12 @@ gu_fullform_enum_next(GuEnum* self, void* to, GuPool* pool)
|
|||||||
while (st->seq_idx < n_seqs) {
|
while (st->seq_idx < n_seqs) {
|
||||||
PgfSymbols* syms = gu_seq_index(st->sequences, PgfSequence, st->seq_idx)->syms;
|
PgfSymbols* syms = gu_seq_index(st->sequences, PgfSequence, st->seq_idx)->syms;
|
||||||
GuString tokens = pgf_get_tokens(syms, 0, pool);
|
GuString tokens = pgf_get_tokens(syms, 0, pool);
|
||||||
|
|
||||||
|
if (!gu_string_is_prefix(st->prefix, tokens)) {
|
||||||
|
st->seq_idx = n_seqs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (strlen(tokens) > 0 &&
|
if (strlen(tokens) > 0 &&
|
||||||
gu_seq_index(st->sequences, PgfSequence, st->seq_idx)->idx != NULL) {
|
gu_seq_index(st->sequences, PgfSequence, st->seq_idx)->idx != NULL) {
|
||||||
entry = gu_new(PgfFullFormEntry, pool);
|
entry = gu_new(PgfFullFormEntry, pool);
|
||||||
@@ -2609,7 +2616,7 @@ gu_fullform_enum_next(GuEnum* self, void* to, GuPool* pool)
|
|||||||
st->seq_idx++;
|
st->seq_idx++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
st->seq_idx++;
|
st->seq_idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2623,6 +2630,7 @@ pgf_fullform_lexicon(PgfConcr *concr, GuPool* pool)
|
|||||||
PgfFullFormState* st = gu_new(PgfFullFormState, pool);
|
PgfFullFormState* st = gu_new(PgfFullFormState, pool);
|
||||||
st->en.next = gu_fullform_enum_next;
|
st->en.next = gu_fullform_enum_next;
|
||||||
st->sequences = concr->sequences;
|
st->sequences = concr->sequences;
|
||||||
|
st->prefix = "";
|
||||||
st->seq_idx = 0;
|
st->seq_idx = 0;
|
||||||
return &st->en;
|
return &st->en;
|
||||||
}
|
}
|
||||||
@@ -2640,6 +2648,33 @@ pgf_fullform_get_analyses(PgfFullFormEntry* entry,
|
|||||||
pgf_morpho_iter(entry->idx, callback, err);
|
pgf_morpho_iter(entry->idx, callback, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuEnum*
|
||||||
|
pgf_lookup_word_prefix(PgfConcr *concr, GuString prefix,
|
||||||
|
GuPool* pool, GuExn* err)
|
||||||
|
{
|
||||||
|
if (concr->sequences == NULL) {
|
||||||
|
GuExnData* err_data = gu_raise(err, PgfExn);
|
||||||
|
if (err_data) {
|
||||||
|
err_data->data = "The concrete syntax is not loaded";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PgfFullFormState* state = gu_new(PgfFullFormState, pool);
|
||||||
|
state->en.next = gu_fullform_enum_next;
|
||||||
|
state->sequences = concr->sequences;
|
||||||
|
state->prefix = prefix;
|
||||||
|
state->seq_idx = 0;
|
||||||
|
|
||||||
|
if (!gu_seq_binsearch_index(concr->sequences, pgf_sequence_order,
|
||||||
|
PgfSequence, (void*) prefix,
|
||||||
|
&state->seq_idx)) {
|
||||||
|
state->seq_idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &state->en;
|
||||||
|
}
|
||||||
|
|
||||||
// The 'pre' construction needs a special handling since
|
// The 'pre' construction needs a special handling since
|
||||||
// it cannot be sorted alphabetically (a single pre contains
|
// it cannot be sorted alphabetically (a single pre contains
|
||||||
// many alternative tokens).
|
// many alternative tokens).
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ void
|
|||||||
pgf_fullform_get_analyses(PgfFullFormEntry* entry,
|
pgf_fullform_get_analyses(PgfFullFormEntry* entry,
|
||||||
PgfMorphoCallback* callback, GuExn* err);
|
PgfMorphoCallback* callback, GuExn* err);
|
||||||
|
|
||||||
|
GuEnum*
|
||||||
|
pgf_lookup_word_prefix(PgfConcr *concr, GuString prefix,
|
||||||
|
GuPool* pool, GuExn* err);
|
||||||
|
|
||||||
PgfExprEnum*
|
PgfExprEnum*
|
||||||
pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat,
|
pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat,
|
||||||
GuString sentence, double heuristics,
|
GuString sentence, double heuristics,
|
||||||
|
|||||||
Reference in New Issue
Block a user