Mostly working!
This commit is contained in:
@@ -151,6 +151,17 @@ class DefinitionSection(TypedDict):
|
||||
sls: NotRequired[list[str]]
|
||||
sseq: Any # list[list[Pair]]
|
||||
|
||||
class UndefinedRunOn(TypedDict):
|
||||
ure: str
|
||||
fl: str
|
||||
utxt: NotRequired[list[list[Pair]]]
|
||||
ins: NotRequired[list[Inflection]]
|
||||
lbs: NotRequired[list[str]]
|
||||
prs: NotRequired[list[Pronunciation]]
|
||||
sls: NotRequired[list[str]]
|
||||
vrs: NotRequired[list[Variant]]
|
||||
|
||||
|
||||
DefinedRunOn = TypedDict(
|
||||
"DefinedRunOn",
|
||||
{
|
||||
@@ -287,7 +298,7 @@ def fetch(word: str) -> WordType:
|
||||
|
||||
def soundUrl(sound: Sound, fmt="ogg") -> QUrl:
|
||||
"""Create a URL from a PRS structure."""
|
||||
base = f"https://media.merriam-webster.com/audio/prons/en/us/{fmt}"
|
||||
base = f"audio://media.merriam-webster.com/audio/prons/en/us/{fmt}"
|
||||
audio = sound["audio"]
|
||||
m = re.match(r"(bix|gg|[a-zA-Z])", audio)
|
||||
if m:
|
||||
@@ -345,10 +356,26 @@ def do_prs(frag: Fragment, prs: list[Pronunciation] | None) -> None:
|
||||
return
|
||||
|
||||
|
||||
def do_aq(aq: AttributionOfQuote | None) -> list[Line]:
|
||||
def do_aq(aq: AttributionOfQuote | None) -> Line:
|
||||
assert aq is not None
|
||||
raise NotImplementedError("aq")
|
||||
return []
|
||||
r = Resources()
|
||||
frag = Fragment()
|
||||
if 'auth' in aq:
|
||||
frag.addText(aq['auth']+', ', r.subduedFormat)
|
||||
if 'source' in aq:
|
||||
frag.addText(aq['source'], r.subduedFormat)
|
||||
if 'aqdate' in aq:
|
||||
frag.addText(', '+aq['aqdate'], r.subduedFormat)
|
||||
if 'subsource' in aq:
|
||||
ss = trycast(SubSource, aq['subsource'])
|
||||
assert ss is not None
|
||||
if 'source' in ss:
|
||||
frag.addText(', '+ss['source'], r.subduedFormat)
|
||||
if 'aqdate' in ss:
|
||||
frag.addText(', '+ss['aqdate'], r.subduedFormat)
|
||||
line = Line()
|
||||
line.addFragment(frag)
|
||||
return line
|
||||
|
||||
|
||||
def do_vis(vis: list[VerbalIllustration] | None, indent=0) -> list[Line]:
|
||||
@@ -364,7 +391,7 @@ def do_vis(vis: list[VerbalIllustration] | None, indent=0) -> list[Line]:
|
||||
line.addFragment(frag)
|
||||
lines.append(line)
|
||||
if "aq" in vi:
|
||||
lines += do_aq(trycast(AttributionOfQuote, vi["aq"]))
|
||||
lines.append(do_aq(trycast(AttributionOfQuote, vi["aq"])))
|
||||
return lines
|
||||
|
||||
|
||||
@@ -688,7 +715,32 @@ def do_dros(dros: list[DefinedRunOn]|None) -> list[Line]:
|
||||
raise NotImplementedError(f"Key of {k}")
|
||||
return lines
|
||||
|
||||
|
||||
def do_uros(uros: list[UndefinedRunOn]|None) -> list[Line]:
|
||||
assert uros is not None
|
||||
r = Resources()
|
||||
lines: list[Line] = []
|
||||
for uro in uros:
|
||||
frag = Fragment()
|
||||
text = re.sub(r'\*', '', uro['ure'])
|
||||
frag.addText(text, r.labelFormat)
|
||||
if 'prs' in uro:
|
||||
do_prs(frag, uro['prs'])
|
||||
frag.addText(' '+uro['fl'],r.textFormat) # r.linkFormat
|
||||
line = Line()
|
||||
line.addFragment(frag)
|
||||
lines.append(line)
|
||||
if 'utxt' in uro:
|
||||
for entry in uro['utxt']:
|
||||
for pair in entry:
|
||||
if pair['objType'] == 'vis':
|
||||
lines += do_vis(trycast(list[VerbalIllustration], pair['obj']))
|
||||
elif pair['objType'] == 'uns':
|
||||
(newFrags, newLines) = do_uns(trycast(list[list[list[Pair]]],pair['obj']),0)
|
||||
line = Line()
|
||||
line.addFragment(newFrags)
|
||||
lines.append(line)
|
||||
lines += newLines
|
||||
return lines
|
||||
def getDef(defines: Any) -> list[Line]:
|
||||
Line.setParseText(parseText)
|
||||
workList = restructure(defines)
|
||||
@@ -786,6 +838,10 @@ def getDef(defines: Any) -> list[Line]:
|
||||
lines += do_def(define)
|
||||
except NotImplementedError:
|
||||
raise
|
||||
if "uros" in work:
|
||||
print(json.dumps(work['uros'],indent=2))
|
||||
uros = trycast(list[UndefinedRunOn], work['uros'])
|
||||
lines += do_uros(uros)
|
||||
if "dros" in work:
|
||||
dros = trycast(list[DefinedRunOn], work["dros"])
|
||||
if len(phrases) < 1:
|
||||
@@ -815,6 +871,7 @@ def getDef(defines: Any) -> list[Line]:
|
||||
"shortdef",
|
||||
"vrs",
|
||||
"dros",
|
||||
'uros',
|
||||
]:
|
||||
raise NotImplementedError(f"Unknown key {k} in work")
|
||||
if len(phrases) > 0:
|
||||
@@ -845,10 +902,10 @@ def replaceCode(code:str) -> tuple[str, QTextCharFormat]:
|
||||
token = fields[0]
|
||||
if token == 'a_link':
|
||||
text = fields[1]
|
||||
fmt.setAnchorHref(fields[1])
|
||||
fmt.setAnchorHref('auto://'+fields[1])
|
||||
elif token in ['d_link', 'et_link', 'mat', 'sx', 'i_link']:
|
||||
text = fields[1]
|
||||
pre = 'word://'
|
||||
pre = 'word:///'
|
||||
if fields[2] == '':
|
||||
fmt.setAnchorHref(pre+fields[1])
|
||||
else:
|
||||
@@ -859,18 +916,18 @@ def replaceCode(code:str) -> tuple[str, QTextCharFormat]:
|
||||
fmt.setFontCapitalization(QFont.Capitalization.SmallCaps)
|
||||
elif token == 'dxt':
|
||||
if fields[3] == 'illustration':
|
||||
fmt.setAnchorHref('article://'+fields[2])
|
||||
fmt.setAnchorHref('article:///'+fields[2])
|
||||
elif fields[3] == 'table':
|
||||
fmt.setAnchorHref('table://'+fields[2])
|
||||
fmt.setAnchorHref('table:///'+fields[2])
|
||||
elif fields[3] != "":
|
||||
fmt.setAnchorHref('sense://'+fields[3])
|
||||
fmt.setAnchorHref('sense:///'+fields[3])
|
||||
else:
|
||||
fmt.setAnchorHref('word://'+fields[1])
|
||||
fmt.setAnchorHref('word:///'+fields[1])
|
||||
elif token == 'et_link':
|
||||
if fields[2] != '':
|
||||
fmt.setAnchorHref('etymology://'+fields[2])
|
||||
fmt.setAnchorHref('etymology:///'+fields[2])
|
||||
else:
|
||||
fmt.setAnchorHref('etymology://' + fields[1])
|
||||
fmt.setAnchorHref('etymology:///' + fields[1])
|
||||
else:
|
||||
raise NotImplementedError(f"Token {code} not implimented")
|
||||
fmt.setForeground(r.linkColor)
|
||||
|
||||
Reference in New Issue
Block a user