Skip to content

Commit

Permalink
linted and blackened notebooks using jupytext
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkroorda committed Jul 1, 2021
1 parent e0c1985 commit cc5cd94
Show file tree
Hide file tree
Showing 3 changed files with 477 additions and 366 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
select = C,E,F,W,B,B950
ignore = E203, E501, W503
builtins = C,E,Eall,Es,F,Fall,Fs,L,N,S,T,TF
175 changes: 96 additions & 79 deletions programs/remains.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,34 @@
}
],
"source": [
"TF.info('Writing {} trees'.format(rootType))\n",
"treeFile = '{}/trees-BHSA.txt'.format(OUTPUTDIR)\n",
"with open(treeFile, 'w') as trees:\n",
" verseLabel = ''\n",
"TF.info(\"Writing {} trees\".format(rootType))\n",
"treeFile = \"{}/trees-BHSA.txt\".format(OUTPUTDIR)\n",
"with open(treeFile, \"w\") as trees:\n",
" verseLabel = \"\"\n",
" s = 0\n",
" chunk = 10000\n",
" sc = 0\n",
" for node in F.otype.s(rootType):\n",
" if node in skip: continue\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(node, 'r', getTag, rev=False, leafNumbers=False)\n",
" trees.write('\\n#{}\\tnode={}\\tbSlot={}\\t{}\\n{}\\n'.format(\n",
" '{} {}:{}'.format(*T.sectionFromNode(node)), \n",
" node,\n",
" bSlot, \n",
" wordsRep,\n",
" treeRep,\n",
" ))\n",
" if node in skip:\n",
" continue\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(\n",
" node, \"r\", getTag, rev=False, leafNumbers=False\n",
" )\n",
" trees.write(\n",
" \"\\n#{}\\tnode={}\\tbSlot={}\\t{}\\n{}\\n\".format(\n",
" \"{} {}:{}\".format(*T.sectionFromNode(node)),\n",
" node,\n",
" bSlot,\n",
" wordsRep,\n",
" treeRep,\n",
" )\n",
" )\n",
" s += 1\n",
" sc += 1\n",
" if sc == chunk:\n",
" TF.info(\"{} trees written\".format(s))\n",
" sc = 0\n",
"TF.info('{} trees written to {}'.format(s, treeFile))"
"TF.info(\"{} trees written to {}\".format(s, treeFile))"
]
},
{
Expand Down Expand Up @@ -130,29 +135,34 @@
}
],
"source": [
"TF.info('Writing {} trees'.format(rootType))\n",
"treeFile = '{}/trees-BHSA-nodes.txt'.format(OUTPUTDIR)\n",
"with open(treeFile, 'w') as trees:\n",
" verseLabel = ''\n",
"TF.info(\"Writing {} trees\".format(rootType))\n",
"treeFile = \"{}/trees-BHSA-nodes.txt\".format(OUTPUTDIR)\n",
"with open(treeFile, \"w\") as trees:\n",
" verseLabel = \"\"\n",
" s = 0\n",
" chunk = 10000\n",
" sc = 0\n",
" for node in F.otype.s(rootType):\n",
" if node in skip: continue\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(node, 'r', getTagN, rev=False, leafNumbers=False)\n",
" trees.write('\\n#{}\\tnode={}\\tbSlot={}\\t{}\\n{}\\n'.format(\n",
" '{} {}:{}'.format(*T.sectionFromNode(node)), \n",
" node,\n",
" bSlot, \n",
" wordsRep,\n",
" treeRep,\n",
" ))\n",
" if node in skip:\n",
" continue\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(\n",
" node, \"r\", getTagN, rev=False, leafNumbers=False\n",
" )\n",
" trees.write(\n",
" \"\\n#{}\\tnode={}\\tbSlot={}\\t{}\\n{}\\n\".format(\n",
" \"{} {}:{}\".format(*T.sectionFromNode(node)),\n",
" node,\n",
" bSlot,\n",
" wordsRep,\n",
" treeRep,\n",
" )\n",
" )\n",
" s += 1\n",
" sc += 1\n",
" if sc == chunk:\n",
" TF.info(\"{} trees written\".format(s))\n",
" sc = 0\n",
"TF.info('{} trees written to {}'.format(s, treeFile))"
"TF.info(\"{} trees written to {}\".format(s, treeFile))"
]
},
{
Expand Down Expand Up @@ -243,23 +253,32 @@
" vNode = T.nodeFromSection(passage)\n",
" return L.d(vNode, otype=rootType)\n",
"\n",
"\n",
"def showcases(cases, oFile):\n",
" with open(oFile, 'w') as out:\n",
" with open(oFile, \"w\") as out:\n",
" for (sNode, caseText) in cases.items():\n",
" out.write('\\n====================\\n{}\\n{}\\n{} TF-node={}:\\n'.format(\n",
" '{} {}:{}'.format(*T.sectionFromNode(sNode)),\n",
" caseText, \n",
" rootType, \n",
" sNode,\n",
" ))\n",
" for kind in ('e', 'r'):\n",
" out.write('\\nTree based on slot embedding {}\\n\\n'.format(\n",
" 'only' if kind == 'e' else ' and mother+clause_constituent relation'\n",
" ))\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(sNode, kind, getTag, rev=False, leafNumbers=False)\n",
" out.write('{}\\n\\n{}\\n'.format(wordsRep, treeRep))\n",
" out.write('\\nDepth={}\\n'.format(tree.depth(sNode, kind)))\n",
" out.write(tree.debugWriteTree(sNode, kind, legenda=kind=='r'))"
" out.write(\n",
" \"\\n====================\\n{}\\n{}\\n{} TF-node={}:\\n\".format(\n",
" \"{} {}:{}\".format(*T.sectionFromNode(sNode)),\n",
" caseText,\n",
" rootType,\n",
" sNode,\n",
" )\n",
" )\n",
" for kind in (\"e\", \"r\"):\n",
" out.write(\n",
" \"\\nTree based on slot embedding {}\\n\\n\".format(\n",
" \"only\"\n",
" if kind == \"e\"\n",
" else \" and mother+clause_constituent relation\"\n",
" )\n",
" )\n",
" (treeRep, wordsRep, bSlot) = tree.writeTree(\n",
" sNode, kind, getTag, rev=False, leafNumbers=False\n",
" )\n",
" out.write(\"{}\\n\\n{}\\n\".format(wordsRep, treeRep))\n",
" out.write(\"\\nDepth={}\\n\".format(tree.depth(sNode, kind)))\n",
" out.write(tree.debugWriteTree(sNode, kind, legenda=kind == \"r\"))"
]
},
{
Expand All @@ -280,28 +299,30 @@
"source": [
"# below holds for etcbc3, in etcbc4 we have less problem cases\n",
"\n",
"problem_desc = collections.OrderedDict((\n",
" (1131739, \"debug reorder\"),\n",
" (1131712, \"interesting\"), \n",
" (1131701, \"interesting\"),\n",
" (1140469, \"subject clause order\"),\n",
" (passageRoots(('Genesis', 1, 16))[0], \"interesting\"), \n",
" (1164864, \"interesting\"),\n",
" (1143081, \"cyclic mothers\"),\n",
" (1153973, \"cyclic mothers\"),\n",
" (1158971, \"cyclic mothers\"),\n",
" (1158971, \"cyclic mothers\"),\n",
" (1160416, \"cyclic mothers\"),\n",
" (1160464, \"cyclic mothers\"),\n",
" (1161141, \"nested cyclic mothers: C.coor => C.attr => P below first C.coor\"), \n",
" (1163666, \"cyclic mothers\"), \n",
" (1164830, \"cyclic mothers\"), \n",
" (1167680, \"cyclic mothers\"), \n",
" (1170057, \"cyclic mothers\"), \n",
" (1193065, \"cyclic mothers\"), \n",
" (1199681, \"cyclic mothers\"), \n",
" (1199682, \"mother points outside sentence\"),\n",
"))\n",
"problem_desc = collections.OrderedDict(\n",
" (\n",
" (1131739, \"debug reorder\"),\n",
" (1131712, \"interesting\"),\n",
" (1131701, \"interesting\"),\n",
" (1140469, \"subject clause order\"),\n",
" (passageRoots((\"Genesis\", 1, 16))[0], \"interesting\"),\n",
" (1164864, \"interesting\"),\n",
" (1143081, \"cyclic mothers\"),\n",
" (1153973, \"cyclic mothers\"),\n",
" (1158971, \"cyclic mothers\"),\n",
" (1158971, \"cyclic mothers\"),\n",
" (1160416, \"cyclic mothers\"),\n",
" (1160464, \"cyclic mothers\"),\n",
" (1161141, \"nested cyclic mothers: C.coor => C.attr => P below first C.coor\"),\n",
" (1163666, \"cyclic mothers\"),\n",
" (1164830, \"cyclic mothers\"),\n",
" (1167680, \"cyclic mothers\"),\n",
" (1170057, \"cyclic mothers\"),\n",
" (1193065, \"cyclic mothers\"),\n",
" (1199681, \"cyclic mothers\"),\n",
" (1199682, \"mother points outside sentence\"),\n",
" )\n",
")\n",
"fixedSample = (\n",
" 1167680,\n",
" 1167152,\n",
Expand Down Expand Up @@ -330,23 +351,19 @@
"motherKeys = list(sorted(tree.mother))\n",
"for s in range(20):\n",
" r = random.randint(0, len(motherKeys) - 1)\n",
" sNode = tree.getRoot(tree.mother[motherKeys[r]], 'e')[0]\n",
" sample[sNode] = 'random sample in {}s with {}s with mothers'.format(rootType, clauseType)\n",
" sNode = tree.getRoot(tree.mother[motherKeys[r]], \"e\")[0]\n",
" sample[sNode] = \"random sample in {}s with {}s with mothers\".format(\n",
" rootType, clauseType\n",
" )\n",
"for sNode in fixedSample:\n",
" fSample[sNode] = 'random sample in {}s with {}s with mothers'.format(rootType, clauseType)\n",
" fSample[sNode] = \"random sample in {}s with {}s with mothers\".format(\n",
" rootType, clauseType\n",
" )\n",
"\n",
"#showcases(problemDesc, 'tree-notabene.txt')\n",
"#showcases(sample, '{}/trees-{}-random-{}.txt'.format(OUTPUTDIR, VERSION, sampleSize))\n",
"#showcases(fsample, 'trees-fixed-{}.txt'.format(len(fsample)))"
"# showcases(problemDesc, 'tree-notabene.txt')\n",
"# showcases(sample, '{}/trees-{}-random-{}.txt'.format(OUTPUTDIR, VERSION, sampleSize))\n",
"# showcases(fsample, 'trees-fixed-{}.txt'.format(len(fsample)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf8dbbdf-8700-4528-864e-978c3db635e1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit cc5cd94

Please sign in to comment.