# Liblouis: Danish table for 6 dots grade 1.5 (grade 2l) forward and backward translation 1993
#
#  Copyright (C) 2014, 2016-2021, 2023, Bue Vester-Andersen <bue@vester-andersen.dk>
#
#  This file is part of liblouis.
#
#  liblouis is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 2.1 of the
#  License, or (at your option) any later version.
#
#  liblouis is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with liblouis. If not, see
#  <http://www.gnu.org/licenses/>.
#
# Version: Bue Vester-Andersen, December 2022

### Table Metadata

#-name: Dansk lille forkortelse 1993
#-index-name: Danish, partially contracted, 6-dot, 1993
#-display-name: Danish 6-dot partially contracted braille (1993 standard)

#+language: da
#+type: literary
#+contraction: partial
#+grade: 1.5
#+dots: 6
#+direction: both
#+system: ddp
#+version: 1993

# Display opcodes
include da-dk-octobraille_1993.dis

### Spaces

# These ctrl-chars have to have a representation, so that they can be properly converted back and forth.
space \t 2478 CHARACTER TABULATION
space \n 678 LINE FEED (LF)
space \v 1368 LINE TABULATION
space \f 12378 FORM FEED (FF)
space \r 257 CARRIAGE RETURN (CR)
space \x00a0 a

include spaces.uti

### Character definitions

# Definition of dot cells
punctuation ! 235 EXCLAMATION MARK
punctuation " 2356 QUOTATION MARK
punctuation ' 4 APOSTROPHE
punctuation ( 236 LEFT PARENTHESIS
punctuation ) 356 RIGHT PARENTHESIS
punctuation , 2 COMMA
punctuation - 36 HYPHEN-MINUS
punctuation . 3 FULL STOP
punctuation / 34 SLASH
punctuation : 25 COLON
punctuation ; 23 SEMICOLON
punctuation ? 26 QUESTION MARK
lowercase a 1
lowercase b 12
lowercase c 14
lowercase d 145
lowercase e 15
lowercase f 124
lowercase g 1245
lowercase h 125
lowercase i 24
lowercase j 245
lowercase k 13
lowercase l 123
lowercase m 134
lowercase n 1345
lowercase o 135
lowercase p 1234
lowercase r 1235
lowercase s 234
lowercase t 2345
lowercase u 136
lowercase v 1236
lowercase y 13456

#use 8 dots for the following chars to avoid conflict with indicators
lowercase q 123457
lowercase w 24567
lowercase x 13467
lowercase z 13567
punctuation | 4568 VERTICAL LINE
punctuation ~ 467 TILDE (changed by pass 2 to not conflict with indicators
lowercase \x00fc 12567

include digits6Dots.uti

punctuation \x00a7 346 SECTION SIGN (0xa7)

lowercase \x00e5 16 LATIN LETTER A WITH RING ABOVE
lowercase \x00e6 345 LATIN LETTER AE
lowercase \x00f8 246 LATIN LETTER O WITH STROKE

# Uppercase letters
base uppercase A a
base uppercase B b 1
base uppercase C c 1
base uppercase D d 14
base uppercase E e 1
base uppercase F f 12
base uppercase G g 124
base uppercase H h 12
base uppercase I i 2
base uppercase J j 24
base uppercase K k 1
base uppercase L l 12
base uppercase M m 13
base uppercase N n 134
base uppercase O o 13
base uppercase P p 123
base uppercase R r 123
base uppercase S s 23
base uppercase T t 234
base uppercase U u 13
base uppercase V v 123
base uppercase Y y 13456
base uppercase Q q 12345
base uppercase W w 2456
base uppercase X x 1346
base uppercase Z z 1356
base uppercase \x00dc \x00fc 12567
base uppercase \x00c5 \x00e5 LATIN LETTER A WITH RING ABOVE
base uppercase \x00c6 \x00e6 LATIN LETTER AE
base uppercase \x00d8 \x00f8 LATIN LETTER O WITH STROKE

# cover all other Braille patterns
include braille-patterns.cti

# Characters with two or more cells

punctuation # 45-3456 NUMBER SIGN
sign $ 45-256 DOLLAR SIGN
math % 245-356 PERCENT SIGN
sign & 6-12346 AMPERSAND
punctuation * 6-35 ASTERISK
math + 45-235 PLUS SIGN
math < 45-134 LESS-THAN SIGN
math = 45-2356 EQUALS SIGN
math > 45-234 GREATER-THAN SIGN
sign @ 45-1 COMMERCIAL AT
punctuation [ 5-236 LEFT SQUARE BRACKET
punctuation \\ 45-16 REVERSE SLASH
punctuation ] 5-356 RIGHT SQUARE BRACKET
punctuation ^ 45-346 CIRCUMFLEX ACCENT
punctuation _ 45-36 LOW LINE
punctuation ` 4 GRAVE ACCENT
punctuation { 45-246 LEFT CURLY BRACKET
punctuation } 45-135 RIGHT CURLY BRACKET
math \x00f7 45-256 DIVISION SIGN

# Misc unicode characters
include da-dk-6miscChars_1993.cti

# Litdigits
include litdigits6Dots.uti
midendnumericmodechars /,.:^

undefined 26

### Braille indicators and special characters

#hyphen - 36

letsign 6

# No letsign before capital letters or letters with accents

noletsign Ii\x00df\x0149\x0152\x0153

# Emphasis opcodes
emphclass italic
emphclass underline
emphclass bold

begemphphrase italic 56
endemphphrase italic after 56

begemphphrase bold 56
endemphphrase bold after 56

begemphphrase underline 56
endemphphrase underline after 56

capsletter 46
begcapsword 456
endcapsword 6
multind 6-46 letsign capsletter
multind 46-6 capsletter letsign
multind 6-456 letsign begcapsword

numsign 3456
multind 6-3456 letsign numsign

#class of none-space characters that demand double dashes
# Used in context lines later.
#must be the first class defined.
attribute charsWDoubleDash .,?!/:"'() # class w

### Correct - forward translation

# Chars that don't require a space before percent and permille:
attribute charsBeforePercent "(\x201e\x0084\x201c\x0093\x201d\x0094\x00ab\x00bb #class x
noback correct `["%"] *
noback correct !$sx["%"] " %"
noback correct `["\x2030"] *
noback correct !$sx["\x2030"] " \x2030"
noback correct `["\x0089"] *
noback correct !$sx["\x0089"] " \x2030"

# Chars to be treated like digits when switching back to letter mode
attribute extraDigits \x00bc\x00bd\x00be

#Use the "correct" opcode to convert chars that can't be back-translated
# and make the table more simple.

# Dashes
attribute dashes \x2013\x2014\x0096\x0097\x00ad
noback correct %dashes "-"

attribute quotes \x201e\x0084\x201c\x0093\x201d\x0094\x00ab\x00bb 
noback correct %quotes "\""

attribute apostrophes `\x201a\x0082\x2039\x008b\x2018\x0091\x2019\x0092\x203a\x009b\x00b4
noback correct %apostrophes "'"

### Correct - backward translation

# characters that may get mangled by the insertion of extra letsigns
nofor correct "\x2818" "~"
#nofor correct "\x282f" "&"
#nofor correct "\x2814" "*"

# Try to distinguish between times (\x00d7) and bullit (\x2022),
# which share the same Braille representation.
nofor correct `["\x00d7"] "\x2022" 
# nofor correct $d["\s\x00d7\s"]$d * #apparently doesn't work now
nofor correct ["\x00d7"]!$d "\x2022" 
nofor correct !$d["\x00d7"] "\x2022" 

nofor correct "\x28a0" ? # Extraneous endcaps signs
#nofor correct "\x2820" ?
nofor correct "~\\456/" "|"

### Pass 1 - Forward and backward

# Remove space between § and numbers.
noback begnum § 346
begnum §\s 346
begnum §§\s 346-346
always §§ 346-346

# Punctuations, math and numbers
#midnum , 2
#midnum . 3
# the following rule is doubtful, but probably does not apply.
#midnum - 36
endnum - 36
#midnum / 34
#midnum : 25
nofor midnum ^ 346
nofor midnum ^ 45-346

midnum ^ 45-346
midnum \x00d7 45-3

# various back rules for math signs etc.
nofor midnum % 0-245-356-0-3456
nofor endnum % 0-245-356
nofor endnum \x2030 0-245-356-356
nofor midnum \s 3456
nofor midnum \x00d7 45-3-3456
nofor midnum \x00d7 45-3
nofor midnum \x00d7 3-3456

# Punctuation
postpunc ! 235
prepunc " 2356
postpunc " 2356
always /\s 6-34-0
always \s/ 0-6-34
nofor always / 6-34
prepunc - 36
postpunc - 36
nofor always \s-\s 0-36-36-0
always :- 25-36
always ;- 23-36
always --- 36-36-36
always ---- 36-36-36-36
always ----- 36-36-36-36-36
# Star enclosed by parentheses
always (*) 236-35-356

before punctuation before sign always ( 6-236

# these characters must be separated from ")" by a letsign.
attribute SepToRightpar Jj%'\x2030\x0089\x201a\x0082\x2039\x009b\x2018\x0091\x2019\x0092\x203a\x009b
after SepToRightpar always ) 6-356

prepunc ( 236
postpunc ) 356
always .) 3-356
always ( 6-236
always ) 6-356

# extra back rules for ")"
nofor after punctuation always ) 356
nofor always \x00b0 4-356
nofor always ') 4-6-356
nofor always ") 2356-356
nofor endword j) 245-356
nofor always ) 6-356

always ... 3-3-3

#inverted exclamation
always \x00a1 6-256

### Contractions ###

#Special sequences, urls emails and file names.

nocont $
nocont \x005c
nocont @
nocont ://
nocont www

#Words
word at 1
word bliver 12
word den 12346
word der 23456
word det 2346
word de 1456
word du 145
word efter 1356
word eller 15
word en 126
word er 156
word et 346
word for 124
word før 246
word gennem 12456
word gør 1245
word han 13456
word har 125
word hun 136
word hvad 2456
word hvor 34
word jeg 245
word kan 13
word lige 123
word med 134
word men 146
word ned 1246
word når 1345
word og 14
word op 135
word over 1346
word på 1234
word ret 12356
word rigtig 1235
word skal 123456
word som 234
word så 16
word te 1256
word til 2345
word under 12345
word ve 3456
word ved 1236
word være 345

# Common combinations of one word contractions with slash
word af/på 356-34-1234
word du/i 145-34-24
word eller/og 15-34-14
word fra/til 235-34-2345
word han/hun 13456-34-136
word hun/han 136-34-13456
word i/du 24-34-145
word og/eller 14-34-15
word over/under 1346-34-12345
word på/af 1234-34-356
word til/fra 2345-34-235
word under/over 12345-34-1346

# no backtrans of ^1 and `2. use contractions
nofor always eta 346-1
nofor always etb 346-12
always etc 346-14

# Ensure no one-letter word contraction before or after a dash

endword -af 36-1-124
begword af- 1-124-36
endword -altid 36-1-2345-145
begword altid- 1-2345-145-36
endword -at 36-1-2345
endword -a 36-6-1
begword at- 1-2345-36
endword -og 36-135-1245
endword -c 36-6-14
begword og- 135-1245-36
endword -du 36-145-136
endword -d 36-6-145
begword du- 145-136-36
endword -efter 36-15-124-2345-156
endword -z 36-6-1356
begword efter- 15-124-2345-156-36
midword -efter- 36-1356-36
endword -e 36-6-15
endword -for 36-124-1346
endword -f 36-6-124
begword for- 124-1346-36
endword -fra 36-124-1235-1
begword fra- 124-1235-1-36
endword -g 36-6-1245
endword -gennem 36-1245-126-1246-134
begword gennem- 1245-126-1246-134-36
endword -ham 36-125-1-134
begword ham- 125-1-134-36
endword -han 36-125-1-1345
endword -y 36-6-13456
begword han- 125-1-1345-36
endword -har 36-125-1-1235
endword -h 36-6-125
begword har- 125-1-1235-36
endword -hun 36-125-136-1345
endword -u 36-6-136
begword hun- 125-136-1345-36
endword -j 36-6-245
endword -kan 36-13-1-1345
endword -k 36-6-13
begword kan- 13-1-1345-36
endword -lige 36-123-24-12456
endword -l 36-6-123
begword lige- 123-24-12456-36
endword -med 36-146-145
endword -m 36-6-134
begword med- 146-145-36
endword -men 36-134-126
begword men- 134-126-36
endword -ned 36-1246-145
begword ned- 1246-145-36
endword -når 36-1345-16-1235
endword -n 36-6-1345
begword når- 1345-16-1235-36
endword -op 36-135-1234
endword -o 36-6-135
begword op- 135-1234-36
endword -over 36-135-1236-156
endword -x 36-6-1346
begword over- 135-1236-156-36
endword -på 36-1234-16
endword -p 36-6-1234
begword på- 1234-16-36
midword -på- 36-1234-36
endword -ret 36-1235-346
begword ret- 1235-346-36
midword -ret- 36-12356-36
endword -rigtig 36-1235-35-2345-35
endword -r 36-6-1235
begword rigtig- 1235-35-2345-35-36
midword -rigtig- 36-1235-36
endword -skal 36-123456-1-123
begword skal- 123456-1-123-36
midword -skal- 36-123456-36
endword -som 36-234-135-134
endword -s 36-6-234
begword som- 234-135-134-36
midword -som- 36-234-36
endword -så 36-234-16
endword -å 36-6-16
begword så- 234-16-36
endword -til 36-2345-24-123
endword -t 36-6-2345
begword til- 2345-24-123-36
midword -til- 36-2345-36
endword -under 36-136-1345-23456
begword under- 136-1345-23456-36
midword -under- 36-12345-36
endword -ved 36-1236-15-145
endword -v 36-6-1236
begword ved- 1236-15-145-36
midword -ved- 36-1236-36


### Context rules - forward translation

# Exclamation at beginning of string
noback context `["!"] @6-235

# Ensure two dashes where appropriate.
noback context $w["-"]$w @36
noback context $sw["-"]$sw @36-36
noback context `["-"]$sw @36-36
noback context $sw["-"]~ @36-36
noback context !$sw["-"]~ @36
noback context `["-"]~ @36-36

# Ensure letsign between letter and numsign
noback context $l[]$D @6

# No "nd", "hv", "or", or "st" after a digit and a letsign
noback context $dy["hv"] @6-125-1236
noback context $dy$Spm["hv"] @6-125-1236
noback context $dy["nd"] @6-1345-145
noback context $dy$Spm["nd"] @6-1345-145
noback context $dy["or"] @6-135-1235
noback context $dy$Spm["or"] @6-135-1235
noback context $dy["st"] @6-234-2345
noback context $dy$Spm["st"] @6-234-2345
noback context $dy["te"] @6-2345-15
noback context $dy$Spm["te"] @6-2345-15


#ensure dot 6 between a digit and a letter
noback context $dy[]$u @6
noback context $dy$Spm.[]$u @6

### context - backward translation

# Ensure the correct number of dashes
nofor context @36[@36-36] "--"
nofor context [@36-36]@36 "--"
nofor context $w[@36-36]$w "--"
nofor context $sw[@36-36]$sw "-"
nofor context `[@36-36]$sw "-"
nofor context $sw[@36-36]~ "-"
nofor context `@36-36~ "-"


### Pass 2 - forward translation

# Correct chars defined as 8 dots because they include letsign
noback pass2 @467 @45-6
noback pass2 @4568 @45-456
noback pass2 @123457 @6-12345
noback pass2 @24567 @6-2456
noback pass2 @13467 @6-1346
noback pass2 @13567 @6-1356
noback pass2 @12567 @6-1256

noback pass2 @6-5 @5 # no letsign before letters with accent
noback pass2 @6-46-5 @46-5 # no letsign before cap letters with accent
noback pass2 _$D[@6-46-6] *
noback pass2 _$D[@6-46] *
noback pass2 @6-46-6 @46-6 # Ensure correct order and no double letsign
noback pass2 @6-46 @46-6 # Ensure correct order

### Pass 2 - backward

# Insert letsign between number (with extra punctuation) and capsletter sign
#nofor pass2 @3456$l.$Spm$l.@3$l.@3[]@46 @6
#nofor pass2 @3456$l.$Spm$l.@3[]@46 @6
#nofor pass2 @3456$l.$Spm$Spm[]@46 @6
#nofor pass2 @3456$l.$Spm[]@46 @6

## Insert letsign between number (with extra punctuation) and capsword sign
#nofor pass2 @3456$l.$Spm$l.@3$l.@3[]@456 @6
#nofor pass2 @3456$l.$Spm$l.@34$l.@34[]@456 @6
#nofor pass2 @3456$l.$Spm$l.@36$l.@36[]@456 @6
#nofor pass2 @3456$l.$Spm$l.@3[]@456 @6
#nofor pass2 @3456$l.$Spm$l.@34[]@456 @6
#nofor pass2 @3456$l.$Spm$l.@36[]@456 @6
#nofor pass2 @3456$l.$Spm$Spm[]@456 @6
#nofor pass2 @3456$l.$Spm[]@456 @6
#nofor pass2 @3456$l.[]@456 @6

### Pass 3 - forward translation

# Ensure there is only one letsign
noback pass3 @6-6 @6

# Ensure there is only one emphasis sign
noback pass3 @56-56 @56
noback pass3 @56-56-56 @56

### Pass 3 - backward translation

# Save letters that have been defined with letsign as part of their definitions
nofor pass3 @6-12345 @6-123457
nofor pass3 @6-2456 @6-24567
nofor pass3 @6-1346 @6-13467
nofor pass3 @6-1356 @13567
nofor pass3 @6-1256 @6-12567

# save ~ and |  before inserting extra letsigns and endcapsword in pass 2.
nofor pass3 @45-6 @467 # Create alternative representation of "~"
nofor pass3 @45-456 @4568
