การสะกดการันต์ในยุคกลาง


9

งาน

งานของคุณคือการแปลงข้อความเป็นการสะกดการันต์ในยุคกลาง

รายละเอียด

  1. jจะถูกแปลงiและการJI
  2. uและUที่จุดเริ่มต้นของคำจะถูกแปลงเป็นvและVตามลำดับ
  3. vและVที่ใดก็ได้ยกเว้นจุดเริ่มต้นของคำจะถูกแปลงเป็นuและUตามลำดับ
  4. sจะถูกแปลงเป็นſ(U + 017F) sเว้นแต่ในตอนท้ายของคำหรือนำหน้าด้วยอีก

รายละเอียด

  • abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZคำที่ถูกกำหนดให้เป็นลำดับของตัวอักษรใน
  • ทุกคำจะมีตัวอักษรอย่างน้อยสองตัว
  • ข้อมูลที่ป้อนจะประกอบด้วยอักขระ ASCII ที่พิมพ์ได้เท่านั้น(U + 0020 - U + 007E)
  • sจะมีการเกิดขึ้นของมากกว่าสองติดต่อกัน นั่นคือsssจะไม่เป็นสตริงย่อยของอินพุต

Testcases

คำเดี่ยว:

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_

ทั้งย่อหน้า:

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.

SHA-256กัญชาของการส่งออกของ testcase ที่ผ่านมาคือ

5641899e7d55e6d1fc6e9aa4804f2710e883146bac0e757308afc58521621644

คำปฏิเสธ

Medievall orthographie ไม่ได้เป็นเช่นนั้น Pleaſe อย่าบ่นถ้าคุณ ſhall ſee olde จองกับออร์โธกราฟที่แตกต่าง


1
"คุณได้รับอนุญาตให้ใช้ f แทน ſ ในเอาต์พุต" ดังนั้นโดยทั่วไปไม่มีแรงจูงใจให้ใช้ ſ เนื่องจากใช้เวลามากกว่าไบต์
ทำให้เสียชีวิต

1
@ ทำให้ยุติธรรมจุด ลบที่หนึ่ง
Leun Nun

@LeakyNun เราจะนับſเป็น 1 ไบต์ได้ไหม
R. Kap

มีแรงจูงใจจริง ๆ ในรูปแบบของ ff ที่ถูกเปลี่ยนเป็น fs ในอัลกอริทึมบางอย่างถ้าไม่ได้ใช้
มะนาวที่ถูกทำลายได้

1
ไม่ควรSuper-viseกลายเป็นSuper-viſe?
R. Kap

คำตอบ:


3

SED, 144 140 111 ไบต์

บันทึกแล้ว 29 ไบต์ขอบคุณ 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
คุณกล้าวิญญาณที่กล้าหาญ
Alexander - Reinstate Monica

คุณสามารถตัดจำนวนไบต์โดยใช้เพียง -e1 ใช้;s ในระหว่างคำสั่ง
NoOne อยู่ที่นี่

ฉันไม่รู้ว่าคุณสามารถทำได้ ขอบคุณ !!
Riley

2

Python 3 ( 128 126 ไบต์)

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)รู้สึกมากเกินไปกับ xor ต่อสายอักขระเดี่ยว แต่บางที Pythonista จริง ๆ อาจแนะนำกอล์ฟ แต่ก็สะดวกมากที่^3พอเพียงที่จะแลกเปลี่ยนและi <-> ju <-> v

NB สิ่งเดียวที่นี่ซึ่งจะต้องมีงูหลาม 3 เป็นอักขระ Unicode: งูหลาม 2 Non-ASCII character '\xc5' <snip> but no encoding declaredบ่น


คุณไม่ควรใช้\bเนื่องจาก\bใช้คำจำกัดความของคำที่มีตัวเลขและขีดล่าง
Leun Nun

@LeakyNun อืม ในขณะที่ฉันกำลังหาวิธีแก้ไขคุณช่วยเพิ่มกรณีทดสอบได้ไหม
ปีเตอร์เทย์เลอร์


@PeterTaylor เดี๋ยวก่อนมันจะทำยังไงดี?
R. Kap

@ R.Kap มันทำให้ regex case-insensitive
ปีเตอร์เทย์เลอร์


1

Python 3.5, 124 116 111 118 125 144 142 ไบต์:

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)

ดูเหมือนว่าจะเป็นงานที่สมบูรณ์แบบสำหรับการแสดงออกปกติ !


1
คุณสามารถใช้J|jแทน[Jj]
แม่ชีรั่วที่

1

JavaScript (ES6), 154

การใช้ parseInt เพื่อระบุตัวอักษร หมายเหตุ: ลวก ๆ แต่โชคดี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``

น้อย golfed

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``

ทดสอบ

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 ไบต์

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

คำอธิบาย: เนื่องจาก JavaScript regexp ไม่มี lookbehind ฉันจึงแยกสตริงออกเป็นคำซึ่งทำให้ฉันสามารถใช้^และ\Bเป็นตัวอักษรเชิงลบและเป็นบวก lookbehinds ssถูกจัดการด้วยการจับคู่แยกด้วยนิพจน์การแทนที่เล็กน้อยที่น่าอึดอัดใจซึ่งใช้ไบต์น้อยกว่าการแทนที่เฉพาะอักขระตัวแรกของcหรือเพิ่มส่วนเพิ่มเติมsทั้งสองสตริงและใช้สตริงย่อยที่ตรงกัน


c=>"iIvVuUſ"["jJuUvVs".search(c)]||"ſs"เป็นสิ่งที่ดี 👍🏻
จอร์แดน


0

Ruby, 85 + 1 = 86 ไบต์

ทำงานด้วยruby -p(+1 ไบต์สำหรับการpตั้งค่าสถานะ) ใช้อินพุตบน stdin

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

ทำการทดสอบบน ideone (ห่อด้วยแลมบ์ดาที่นั่นเพราะคุณไม่สามารถให้ธงแก่ ideone ได้): http://ideone.com/AaZ8ya

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.