Ortografia medievale


9

Compito

Il tuo compito è convertire un testo in ortografia medievale.

Dettagli

  1. jviene convertito in ie Jin I.
  2. ue Uall'inizio delle parole vengono convertite in ve Vrispettivamente.
  3. ve Vovunque tranne l'inizio delle parole vengono convertiti in ue Urispettivamente.
  4. sviene convertito in ſ(U + 017F) a meno che alla fine della parola o preceduto da un altro s.

Specifiche

  • Una parola è definita come una sequenza di lettere in abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.
  • Tutte le parole avranno almeno due lettere.
  • L'input consisterà solo di caratteri ASCII stampabili (U + 0020 - U + 007E).
  • Non si verificheranno più di due consecutivi s. Cioè, sssnon sarà una sottostringa dell'input.

Casi test

Parole individuali:

Input       Output
------------------------
Joy         Ioy
joy         ioy
Universe    Vniuerſe
universe    vniuerſe
Success     Succeſs
successfull ſucceſsfull
Supervise   Superuiſe
supervise   ſuperuiſe
Super-vise  Super-viſe
I've        I've
majors      maiors
UNIVERSE    VNIUERSE
0universe   0vniuerſe
0verify     0verify
I0ve        I0ve
_UU_          _VU_
_VV_          _VU_
ss_         ſs_

Intero paragrafo:

Input:  Christian Reader, I have for thy use collected this small Concordance, with no small labour. For being to comprise much in little roome, I was to make choyse of the most principall and usefull places, and to rank them under such words as I thought most essentiall and materiall in the sentence, because the scant roome allotted unto me, would not permit that I should expresse them under every word in the verse, as it is the manner in large Concordances.

Output: Chriſtian Reader, I haue for thy vſe collected this ſmall Concordance, with no ſmall labour. For being to compriſe much in little roome, I was to make choyſe of the moſt principall and vſefull places, and to rank them vnder ſuch words as I thought moſt eſsentiall and materiall in the ſentence, becauſe the ſcant roome allotted vnto me, would not permit that I ſhould expreſse them vnder euery word in the verſe, as it is the manner in large Concordances.

L' hash SHA-256 dell'output dell'ultima testcase è:

5641899e7d55e6d1fc6e9aa4804f2710e883146bac0e757308afc58521621644

disconoscimento

L'ortografia medievale non è così importante. Per favore, non competere se guardi vecchi libri con una ortografia diversa.


1
"Puoi usare f invece di ſ nell'output." Quindi non c'è praticamente alcun incentivo per usare ſ poiché ci vogliono più byte.
Fatalizza il

1
@Fatalize Fair point. Rimosso quello.
Leaky Nun,

@LeakyNun Possiamo quindi contare ſcome 1 byte?
R. Kap

c'è effettivamente un incentivo sotto forma di ff che viene modificato in fs in alcuni algoritmi se ſ non è stato usato
Destructible Lemon

1
Non dovrebbe Super-visediventare Super-viſe?
R. Kap

Risposte:


3

SED, 144 140 111 byte

salvato 29 byte grazie a NoOneIsHere

-r -e'y/j/i/g;y/J/I/g;s/ u/ v/g;s/ U/ V/g;s/^u/v/g;s/^U/V/g;s/([^s])s(\w)/\1ſ\2/g;s/(\w)v/\1u/g;s/(\w)V/\1U/g'

1
Anima coraggiosa e coraggiosa.
Alexander - Ripristina Monica il

Puoi tagliare molti byte usando solo 1 -e. Usa le ;istruzioni tra.
NoOneIsHere

Non sapevo che potessi farlo. Grazie!!
Riley,

2

Python 3 ( 128 126 byte)

import re;lambda k:re.sub("(?<!s)s(?=[a-zA-Z])",'ſ',re.sub("(?i)j|(?<![a-z])u|(?<=[a-z])v",lambda c:chr(ord(c.group())^3),k))

chr(ord(c.group())^3)sembra eccessivo xor una stringa di un singolo carattere, ma forse un vero Pythonista può suggerire un golf. Tuttavia, è molto conveniente che è ^3sufficiente scambiare i <-> je u <-> v.

NB L'unica cosa che richiede Python 3 è il carattere Unicode: Python 2 si lamenta Non-ASCII character '\xc5' <snip> but no encoding declared.


Non dovresti usare \bpoiché \busa la definizione di una parola che include cifre e caratteri di sottolineatura.
Leaky Nun,

@LeakyNun, hmm. Mentre cerco una soluzione, potresti aggiungere alcuni casi di test?
Peter Taylor,

@ R.Kap. (?i).
Peter Taylor,

@PeterTaylor Aspetta, che cosa fa?
R. Kap

@ R.Kap, rende il regex insensibile alle maiuscole.
Peter Taylor,


1

Python 3.5, 124 116 111 118 125 144 142 byte:

import re;lambda k:re.sub("J|j|(?<![a-zA-Z])[uU]|(?<=[a-zA-Z])[Vv]|(?<!s)s(?=[a-zA-Z])",lambda g:dict(zip('jJuUvVs','iIvVuUſ'))[g.group()],k)

Bene, questo sembra il lavoro perfetto per le espressioni regolari !


1
Puoi usare J|jinvece di[Jj]
Leaky Nun il

1

JavaScript (ES6), 154

Utilizzo di parseInt per identificare i caratteri alfabetici. Nota: casualmente ma per fortuna parseInt('undefined',36)|0è <0

s=>[...s].map((c,i)=>((n=v(c))-19?n==31&p>9?'uU':n!=30|p>9?c=='s'&s[i-1]!=c&v(s[i+1])>9?'?':c+c:'vV':'iI')[p=n,c<'a'|0],p=0,v=c=>parseInt(c,36)|0).join``

Meno golf

s=>
  [...s].map(
  (c,i)=>
  ((n=v(c))-19
  ?n==31&p>9
    ?'uU'
    :n!=30|p>9
      ?c=='s'&s[i-1]!=c&v(s[i+1])>9
        ?'ſ'
        :c+c
      :'vV'
  :'iI')[p=n,c<'a'|0],
  p=0,
  v=c=>parseInt(c,36)|0
).join``

Test

F=
s=>[...s].map((c,i)=>((n=v(c))-19?n==31&p>9?'uU':n!=30|p>9?c=='s'&s[i-1]!=c&v(s[i+1])>9?'ſ':c+c:'vV':'iI')[p=n,c<'a'|0],p=0,v=c=>parseInt(c,36)|0).join``

out=(a,b,c)=>O.textContent+=a+'\n'+b+'\n'+c+'\n\n'

ti='Christian Reader, I have for thy use collected this small Concordance, with no small labour. For being to comprise much in little roome, I was to make choyse of the most principall and usefull places, and to rank them under such words as I thought most essentiall and materiall in the sentence, because the scant roome allotted unto me, would not permit that I should expresse them under every word in the verse, as it is the manner in large Concordances.'
to='Chriſtian Reader, I haue for thy vſe collected this ſmall Concordance, with no ſmall labour. For being to compriſe much in little roome, I was to make choyſe of the moſt principall and vſefull places, and to rank them vnder ſuch words as I thought moſt eſsentiall and materiall in the ſentence, becauſe the ſcant roome allotted vnto me, would not permit that I ſhould expreſse them vnder euery word in the verſe, as it is the manner in large Concordances.'
r=F(ti)
out(to==r?'OK':'KO',ti,r)

test=`Joy         Ioy
joy         ioy
Universe    Vniuerſe
universe    vniuerſe
Success     Succeſs
successfull ſucceſsfull
Supervise   Superuiſe
supervise   ſuperuiſe
Super-vise  Super-viſe
I've        I've
majors      maiors
UNIVERSE    VNIUERSE
0universe   0vniuerſe
0verify     0verify
I0ve        I0ve
_UU_          _VU_
_VV_          _VU_
ss_         ſs_`
.split('\n').map(t=>{
  var [i,o]=t.split(/\s+/),r=F(i)
  out(o==r?'OK':'KO',i,r)
})
#O {width:90%; overflow:auto; white-space: pre-wrap}
<pre id=O></pre>


1

JavaScript (ES6), 111 byte

s=>s.replace(/[a-z]+/gi,w=>w.replace(/j|J|^u|^U|\Bv|\BV|ss|s(?!$)/g,c=>"iIvVuUſ"["jJuUvVs".search(c)]||"ſs"))

Spiegazione: Poiché regexp JavaScript non ha alcun aspetto, ho invece suddiviso la stringa in parole, il che mi ha permesso di utilizzare ^e \Bcome aspetti negativi e positivi. ssviene gestito mediante la corrispondenza separatamente, con l'espressione di sostituzione leggermente scomoda che richiede meno byte rispetto alla sostituzione del solo carattere co all'aggiunta di un extra sa entrambe le stringhe e l'utilizzo della sottostringa corrispondente.


c=>"iIvVuUſ"["jJuUvVs".search(c)]||"ſs"è bello. 👍🏻
Giordania,

0

CJam ( 89 88 byte)

{32|_'`>\'{<*}:A;SqS++3ew{_1="jJuUvVs"#[-4_{_0=A!3*}_{_0=A3*}_{_)A\0='s=>268*}W]=~f^1=}%

Demo online

Non ho mai capito perché CJam non abbia regex, ma dal momento che non c'è una soluzione che non le usa.


0

Rubino, 85 + 1 = 86 byte

Esegui con ruby -p(+1 byte per pflag). Accetta input su stdin.

gsub(/j|(?<=^|[^a-z])u|(?<=[a-z])v|(?<=^|[^s])s(?=[a-z])/i){$&.tr"jJsUuVv","iIfVvUu"}

Esegui i test su ideone (avvolto in un lambda lì perché non puoi dare bandiere a ideone): http://ideone.com/AaZ8ya

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.