diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-03-31 23:49:44 +0200 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:19:28 +0200 |
commit | 5aed7c46cff192311a208dc5e9cf7f81a40771a8 (patch) | |
tree | 4752441e30fb216bdb6dc43da008c6b0d828ad05 /src/core | |
parent | e35445b4e8fecde55b93a4b92037aa0adf70d6d1 (diff) |
Implement TokenStack::lookup method used to lookup the SyntaxDescriptors associated with a certain token.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/parser/stack/TokenStack.cpp | 18 | ||||
-rw-r--r-- | src/core/parser/stack/TokenStack.hpp | 36 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/core/parser/stack/TokenStack.cpp b/src/core/parser/stack/TokenStack.cpp index c20c764..1c26a7c 100644 --- a/src/core/parser/stack/TokenStack.cpp +++ b/src/core/parser/stack/TokenStack.cpp @@ -30,6 +30,24 @@ void TokenStack::pushTokens(const std::vector<SyntaxDescriptor> &tokens, stack.push_back(tokens); } +TokenDescriptor TokenStack::lookup(TokenId token) const +{ + TokenDescriptor res; + if (!stack.empty()) { + for (const SyntaxDescriptor &descr : stack.back()) { + if (descr.close == token) { + res.close.emplace_back(descr); + } + if (descr.shortForm == token) { + res.shortForm.emplace_back(descr); + } + if (descr.open == token) { + res.open.emplace_back(descr); + } + } + } + return res; +} void TokenStack::popTokens() { stack.pop_back(); } TokenSet TokenStack::tokens() const diff --git a/src/core/parser/stack/TokenStack.hpp b/src/core/parser/stack/TokenStack.hpp index 32f181a..d5deafe 100644 --- a/src/core/parser/stack/TokenStack.hpp +++ b/src/core/parser/stack/TokenStack.hpp @@ -38,6 +38,34 @@ namespace ousia { namespace parser_stack { /** + * Structure describing a token once it has been found in the text. Contains + * lists pointing at the corresponding SyntaxDescriptors for the open, close and + * shortForm token types. + */ +struct TokenDescriptor { + /** + * Vector containing the SyntaxDescriptors in which the token occurs as + * "close" token. The Token is first tried to be processed as a "close" + * token. + */ + std::vector<SyntaxDescriptor> close; + + /** + * Vector containing the SyntaxDescriptors in which the token occurs as + * "shortForm" token. Creating a "shortForm" of the referenced ontology + * descriptor is tried next. + */ + std::vector<SyntaxDescriptor> shortForm; + + /** + * Vector containing the SyntaxDescriptors in which the token occurs as + * "open" token. The possibility of using the token in the "open" mode is + * tried in the last step. + */ + std::vector<SyntaxDescriptor> open; +}; + +/** * The TokenStack class is used by the Stack class to collect all currently * enabled user defined tokens. */ @@ -66,6 +94,14 @@ public: void popTokens(); /** + * Returns the TokenDescriptor for the given token. + * + * @param token is the token for which the different forms should be looked + * up. + */ + TokenDescriptor lookup(TokenId token) const; + + /** * Returns a set containing all currently enabled tokens. The set of enabled * tokens are those tokens that were pushed last onto the stack. This set * has to be passed to the TokenizedData instance in order to gather all |