Skip to content

Commit

Permalink
Added some documentation to normalization function, which assures gra…
Browse files Browse the repository at this point in the history
…mmar built with Builder is proper and fixes #12
  • Loading branch information
digitalheir committed Dec 30, 2017
1 parent fdff6da commit b611ccb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/leibnizcenter/cfg/grammar/Grammar.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ public Set<Terminal<T>> getCategories(final Token<T> token) {
ignored -> this.terminals.stream()
.filter(category -> !(category instanceof NonLexicalToken))
.filter(category -> category.hasCategory(token))
.collect(Collectors.toSet())
);
.collect(Collectors.toSet()));
}


Expand Down Expand Up @@ -326,6 +325,10 @@ public Builder<E> addRule(final NonTerminal left, final Category... right) {

/**
* Ensures grammar is proper, i.e. the sum of production probabilities should equal 1.0 for each producible category
*
* @param rules Collection of potentially unweighted rules
* @param semiring Semiring used to compute probabilities
* @return New object containing all rules with normalized probabilities
*/
private MyMultimap<NonTerminal, Rule> normalizeRuleWeights(final MyMultimap<NonTerminal, Rule> rules, final DblSemiring semiring) {
final MyMultimap<NonTerminal, Rule> newRuleMap = new MyMultimap<>();
Expand Down

0 comments on commit b611ccb

Please sign in to comment.