-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding interface for Lushu, implementing context storage structures
- Loading branch information
1 parent
965ce4b
commit 1b48752
Showing
11 changed files
with
325 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ fun main(args: Array<String>) { | |
println( | ||
"options:\nHTML = 0\nC = 1\n" | ||
) | ||
|
||
return | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
Lushu/src/main/kotlin/lushu/ContextGrammar/Grammar/Grammar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Lushu/src/main/kotlin/lushu/ContextGrammar/MapGrammar/ContextTree.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package lushu.ContextGrammar.MapGrammar | ||
|
||
import lushu.ContextGrammar.Grammar.Rules | ||
import lushu.Merger.Lattice.Node.GrammarNode | ||
import lushu.Merger.Merger.Merger | ||
|
||
class ContextTree( | ||
val dsl: DSL = DSL(), | ||
val merger: Merger, | ||
) { | ||
private val root: GrammarNode = GrammarNode() | ||
|
||
private fun string2list(string: String): List<String> { | ||
val woNewline = string.split(Grammar.newlineDelim).joinToString(Grammar.spaceDelim) | ||
return woNewline.split(Grammar.spaceDelim) | ||
} | ||
|
||
private fun insert(context: MutableList<String>, current: GrammarNode? = root) { | ||
if (context.isNullOrEmpty()) { | ||
return | ||
} | ||
|
||
val firstWord = 0 | ||
val word = context[firstWord] | ||
|
||
val func = dsl.getLambdaFunction(word) | ||
val mergeable = dsl.isMergeable(word) | ||
val kleene = dsl.isStarCase(word) | ||
|
||
val wordWoTags = dsl.removeAllTags(word) | ||
|
||
// true if it's the last word in the context | ||
val endOfContext: Boolean = (context.size == 1) | ||
|
||
val updatedCurrent = current?.findOrAddChild( | ||
wordWoTags, | ||
kleene, | ||
mergeable, | ||
func, | ||
endOfContext, | ||
) | ||
|
||
context.removeAt(firstWord) | ||
|
||
if (nextCases[Rules.starCase]) { | ||
addContextRule(context, current) | ||
} else { | ||
addContextRule(context, updatedCurrent) | ||
} | ||
} | ||
|
||
fun insertContext(context: String) { | ||
val contexts = dsl.extractContext(context) | ||
val contextTokens = string2list(context) | ||
insert(contextTokens.toMutableList()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Lushu/src/main/kotlin/lushu/ContextGrammar/MapGrammar/DefaultFunctions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lushu.ContextGrammar.MapGrammar | ||
|
||
class DefaultFunctions { | ||
|
||
private fun print() { | ||
} | ||
|
||
private fun count() { | ||
} | ||
|
||
private fun save() { | ||
} | ||
} |
Oops, something went wrong.