-
Notifications
You must be signed in to change notification settings - Fork 4
WIP: Add swedish short words filter #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carl-textalk
wants to merge
9
commits into
brailleapps:master
Choose a base branch
from
carl-textalk:add-swedish-short-words-filter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
09a8acc
add contracted braille translation table for swedish words
carl-textalk af79c8f
add swedish contracted braille filter class
carl-textalk 2367c81
add contracted braille filter to braillefilter class
carl-textalk f5ac111
implement support for swedish contracted braille step 1
carl-textalk 14e80bd
style fixes
carl-textalk 97215aa
add failing test for soft hyphens
carl-textalk 90e85e5
handle soft hyphens
carl-textalk 6327cad
update swedish contracted braille list with only one char translations
carl-textalk 8e50cc7
remove debug print
carl-textalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
src/org/daisy/dotify/translator/impl/sv_SE/SwedishContractedBrailleFilter.java
This file contains hidden or 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,89 @@ | ||
| package org.daisy.dotify.translator.impl.sv_SE; | ||
|
|
||
| import org.daisy.dotify.common.text.StringFilter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Iterator; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class SwedishContractedBrailleFilter implements StringFilter { | ||
|
|
||
| private HashMap<String, String> contractedBrailleMap; | ||
| private static final String CONTRACTED_BRAILLE_TABLE_PATH = "sv_SE-single-character-contracted-words.xml"; | ||
|
|
||
| public static final String CAPITAL_CHAR_MARKER = "\u2820"; | ||
| public static final String SOFT_HYPHEN = "\u00AD"; | ||
|
|
||
| /** | ||
| * Todo: add support for different grades of contraction. | ||
| * For now only single character contracted words is supported | ||
| */ | ||
| public SwedishContractedBrailleFilter() { | ||
| this.contractedBrailleMap = new HashMap<>(); | ||
| this.loadTable(); | ||
| } | ||
|
|
||
| /** | ||
| * Search and replace with contracted braille. | ||
| * First split the string on space character and go through all words and look for a match in the contractin table. | ||
| * | ||
| * @param str - The string that should be filterd | ||
| * @return the filtered string | ||
| */ | ||
| @Override | ||
| public String filter(String str) { | ||
|
|
||
| String[] words = str.split("\\s"); | ||
| // Handle Edge case with no words. | ||
| if (words.length == 0) { | ||
| return str; | ||
| } | ||
| // Strip string from | ||
| Pattern pattern = Pattern.compile(CAPITAL_CHAR_MARKER + "*([\\p{javaUpperCase}\\p{javaLowerCase}"+SOFT_HYPHEN+"]+)"); | ||
| StringBuilder sb = new StringBuilder(); | ||
| String key, replace; | ||
|
|
||
| for (String word: words) { | ||
| Matcher matcher = pattern.matcher(word); | ||
| if (matcher.find()) { | ||
| key = matcher.group(1).toLowerCase().replace(SOFT_HYPHEN, ""); | ||
| if (this.contractedBrailleMap.containsKey(key)) { | ||
| replace = this.contractedBrailleMap.get(key); | ||
| word = word.substring(0, matcher.start(1)) + replace + word.substring(matcher.end(1)); | ||
| } | ||
| } | ||
| sb.append(word); | ||
| sb.append(" "); | ||
| } | ||
| str = sb.toString().trim(); | ||
| return str; | ||
| } | ||
|
|
||
| /** | ||
| * Loads a table using the Properties class. | ||
| */ | ||
| private void loadTable() { | ||
| URL tableURL = this.getClass().getResource(CONTRACTED_BRAILLE_TABLE_PATH); | ||
| Properties props = new Properties(); | ||
| try { | ||
| props.loadFromXML(tableURL.openStream()); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| return; | ||
| } | ||
| Set<?> keys = props.keySet(); | ||
| for (Iterator<?> it = keys.iterator(); it.hasNext(); ) { | ||
| String key = (String) it.next(); | ||
| contractedBrailleMap.put(key, props.getProperty(key)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
4 changes: 3 additions & 1 deletion
4
src/org/daisy/dotify/translator/impl/sv_SE/messages.properties
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| uncontracted-6-dot=Uncontracted (6-dot) | ||
| uncontracted-6-dot=Uncontracted (6-dot) | ||
| uncontracted-description=Uncontracted Swedish braille | ||
| contracted-6-dot=Contracted (6-dot) | ||
| contracted-description=Contracted Swedish braille | ||
| pre-translated=Pre-translated | ||
| pre-translated-description=Pre-translated braille |
42 changes: 42 additions & 0 deletions
42
src/org/daisy/dotify/translator/impl/sv_SE/sv_SE-single-character-contracted-words.xml
This file contains hidden or 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,42 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> | ||
| <properties> | ||
| <comment>Braille translation table for Swedish short script words.</comment> | ||
|
|
||
| <entry key="att">a</entry> | ||
| <entry key="bli">b</entry> | ||
| <entry key="och">c</entry> | ||
| <entry key="där">d</entry> | ||
| <entry key="eller">e</entry> | ||
| <entry key="från">f</entry> | ||
| <entry key="genom">g</entry> | ||
| <entry key="han">h</entry> | ||
| <entry key="jag">j</entry> | ||
| <entry key="kan">k</entry> | ||
| <entry key="lika">l</entry> | ||
| <entry key="man">m</entry> | ||
| <entry key="när">n</entry> | ||
| <entry key="på">p</entry> | ||
| <entry key="under">q</entry> | ||
| <entry key="har">r</entry> | ||
| <entry key="som">s</entry> | ||
| <entry key="till">t</entry> | ||
| <entry key="utan">u</entry> | ||
| <entry key="vid">v</entry> | ||
| <entry key="vad">w</entry> | ||
| <entry key="över">x</entry> | ||
| <entry key="mycket">y</entry> | ||
| <entry key="efter">z</entry> | ||
| <entry key="är">ä</entry> | ||
|
|
||
| <entry key="en">ê</entry> | ||
| <entry key="med">î</entry> | ||
| <entry key="er">û</entry> | ||
| <entry key="ett">§</entry> | ||
| <entry key="för">ë</entry> | ||
| <entry key="inte">ü</entry> | ||
| <entry key="de">ô</entry> | ||
| <entry key="det">è</entry> | ||
| <entry key="den">\</entry> | ||
| <entry key="var">à</entry> | ||
| </properties> | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.