Skip to content

Commit

Permalink
small fixes in version mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkroorda committed Sep 8, 2022
1 parent 632036c commit 958f894
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 103 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"text-fabric-make = tf.client.make.build:main",
]
},
version='10.2.3',
version='10.2.4',
description="""Processor and browser for Text Fabric Data""",
author="Dirk Roorda",
author_email="text.annotation@icloud.com",
Expand Down
2 changes: 1 addition & 1 deletion text_fabric.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: text-fabric
Version: 10.2.3
Version: 10.2.4
Summary: Processor and browser for Text Fabric Data
Home-page: https://github.com/annotation/text-fabric
Author: Dirk Roorda
Expand Down
2 changes: 1 addition & 1 deletion tf/core/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def silentConvert(arg):
return VERBOSE
if arg is True:
return DEEP
if arg in {VERBOSE, AUTO, TERSE, DEEP}:
if type(arg) is str and arg in {VERBOSE, AUTO, TERSE, DEEP}:
return arg
return not not arg

Expand Down
181 changes: 83 additions & 98 deletions tf/dataset/nodemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@

import sys
import collections
import time
from itertools import chain
from ..core.timestamp import SILENT_D, VERBOSE, AUTO, TERSE, silentConvert

Expand All @@ -152,90 +151,6 @@
TIMESTAMP = None


def _duration():
global TIMESTAMP
if TIMESTAMP is None:
TIMESTAMP = time.time()

interval = time.time() - TIMESTAMP
if interval < 10:
return "{: 2.2f}s".format(interval)
interval = int(round(interval))
if interval < 60:
return "{:>2d}s".format(interval)
if interval < 3600:
return "{:>2d}m {:>02d}s".format(interval // 60, interval % 60)
return "{:>2d}h {:>02d}m {:>02d}s".format(
interval // 3600, (interval % 3600) // 60, interval % 60
)


def caption(
level, heading, silent=SILENT_D, good=None, newLine=True, continuation=False
):
silent = silentConvert(silent)
prefix = "" if good is None else "SUCCES " if good else "FAILURE "
duration = "" if continuation else "{:>11} ".format(_duration())
reportHeading = "{}{}{}".format(duration, prefix, heading)

emit = silent == VERBOSE or silent == AUTO and level in {2, 3, 4} or silent == TERSE and level in {2, 3}

if level == 0: # non-heading message
decoration = "" if continuation else "| "
formattedString = """{}{}""".format(decoration, reportHeading)
elif level == 1: # pipeline level
formattedString = """
##{}##
# {} #
# {} #
# {} #
##{}##
""".format(
"#" * 90,
" " * 90,
"{:<90}".format(reportHeading),
" " * 90,
"#" * 90,
)
elif level == 2: # repo level
formattedString = """
**{}**
* {} *
* {} *
* {} *
**{}**
""".format(
"*" * 90,
" " * 90,
"{:<90}".format(reportHeading),
" " * 90,
"*" * 90,
)
elif level == 3: # task level
formattedString = """
--{}--
- {} -
--{}--
""".format(
"-" * 90,
"{:<90}".format(reportHeading),
"-" * 90,
)
elif level == 4: # caption within task execution
formattedString = """..{}..
. {} .
..{}..""".format(
"." * 90,
"{:<90}".format(reportHeading),
"." * 90,
)
if emit:
if newLine:
print(formattedString)
else:
sys.stdout.write(formattedString)


class Versions:
def __init__(self, api, va, vb, silent=SILENT_D, slotMap=None):
"""Map the nodes of a nodetype between two versions of a TF dataset.
Expand Down Expand Up @@ -281,8 +196,10 @@ def __init__(self, api, va, vb, silent=SILENT_D, slotMap=None):
self.edge = slotMap
self.good = True
for v in (va, vb):
if va not in api:
print(f"No TF-API for version {va} in the `api` parameter.")
if v not in api:
sys.stderr.write(
f"No TF-API for version {va} in the `api` parameter.\n"
)
self.good = False

if not self.good:
Expand All @@ -301,14 +218,17 @@ def __init__(self, api, va, vb, silent=SILENT_D, slotMap=None):
self.Fsb = api[vb].Fs
self.TFa = api[va].TF
self.TFb = api[vb].TF
self.info = self.TFb.info
self.warning = self.TFb.warning
self.error = self.TFb.error

self.diagnosis = {}

def makeNodeMapping(self, nodeType):
edge = self.edge

if edge is None:
print("Cannot make node mapping if no slot mapping is given")
self.error("Cannot make node mapping if no slot mapping is given")
return False

va = self.va
Expand All @@ -323,12 +243,10 @@ def makeNodeMapping(self, nodeType):
Eosb = Eb.oslots.s
otypesa = Fa.otype.s

caption(2, "Mapping {} nodes {} ==> {}".format(nodeType, va, vb))
self.caption(2, f"Mapping {nodeType} nodes {va} ==> {vb}")

diag = {}
caption(
0, "Extending slot mapping {} ==> {} for {} nodes".format(va, vb, nodeType)
)
self.caption(0, f"Extending slot mapping {va} ==> {va} for {nodeType} nodes")
for n in otypesa(nodeType):
slots = Eosa(n)
mappedSlots = set(
Expand Down Expand Up @@ -384,14 +302,14 @@ def makeNodeMapping(self, nodeType):
diag[n] = "e"

self.diagnosis[nodeType] = diag
caption(0, "\tDone")
self.caption(0, "\tDone")

def exploreNodeMapping(self, nodeType):
va = self.va
vb = self.vb
diagnosis = self.diagnosis

caption(4, "Statistics for {} ==> {} ({})".format(va, vb, nodeType))
self.caption(4, "Statistics for {} ==> {} ({})".format(va, vb, nodeType))

diag = diagnosis[nodeType]
total = len(diag)
Expand All @@ -403,14 +321,16 @@ def exploreNodeMapping(self, nodeType):
for (n, dia) in diag.items():
reasons[dia] += 1

caption(0, "\t{:<30} : {:6.2f}% {:>7}x".format("TOTAL", 100, total))
self.caption(-1, "\t{:<30} : {:6.2f}% {:>7}x".format("TOTAL", 100, total))
for stat in STAT_LABELS:
statLabel = STAT_LABELS[stat]
amount = reasons[stat]
if amount == 0:
continue
perc = 100 * amount / total
caption(0, "\t{:<30} : {:6.2f}% {:>7}x".format(statLabel, perc, amount))
self.caption(
-1, "\t{:<30} : {:6.2f}% {:>7}x".format(statLabel, perc, amount)
)

def getDiagnosis(self, node=None, label=None):
"""Show the diagnosis of a mapping.
Expand Down Expand Up @@ -488,7 +408,7 @@ def legend(self):
"""

for (acro, desc) in STAT_LABELS.items():
print(f"{acro} = {desc}")
self.info(f"{acro} = {desc}", tm=False)

def omapName(self):
va = self.va
Expand All @@ -503,7 +423,7 @@ def writeMap(self):
silent = self.silent

fName = self.omapName()
caption(4, "Write edge as TF feature {}".format(fName))
self.caption(4, "Write edge as TF feature {}".format(fName))

edgeFeatures = {fName: edge}
metaData = {
Expand Down Expand Up @@ -719,3 +639,68 @@ def getBestMatches(n, dest):
silent=silent,
)
TFb.warning("Done")

def caption(self, level, heading, good=None, newLine=True, continuation=False):
silent = self.silent
prefix = "" if good is None else "SUCCES " if good else "FAILURE "
reportHeading = "{}{}".format(prefix, heading)

emit = (
silent == VERBOSE
or silent == AUTO
and level in {-1, 2, 3, 4}
or silent == TERSE
and level in {2, 3}
)

if level in {-1, 0}: # non-heading message
decoration = "" if continuation else "| "
formattedString = """{}{}""".format(decoration, reportHeading)
elif level == 1: # pipeline level
formattedString = """
##{}##
# {} #
# {} #
# {} #
##{}##
""".format(
"#" * 90,
" " * 90,
"{:<90}".format(reportHeading),
" " * 90,
"#" * 90,
)
elif level == 2: # repo level
formattedString = """
**{}**
* {} *
* {} *
* {} *
**{}**
""".format(
"*" * 90,
" " * 90,
"{:<90}".format(reportHeading),
" " * 90,
"*" * 90,
)
elif level == 3: # task level
formattedString = """
--{}--
- {} -
--{}--
""".format(
"-" * 90,
"{:<90}".format(reportHeading),
"-" * 90,
)
elif level == 4: # caption within task execution
formattedString = """..{}..
. {} .
..{}..""".format(
"." * 90,
"{:<90}".format(reportHeading),
"." * 90,
)
if emit:
self.info(formattedString, nl=newLine, tm=not continuation, force=True)
4 changes: 3 additions & 1 deletion tf/docs/about/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ See the app-specific tutorials via `tf.about.corpora`.

## 10

## 10.2.2-3
## 10.2.2-4

2022-09-08

Expand All @@ -21,6 +21,8 @@ and many outputs are done in plain text instead of HTML.

Fixes in volume support.

Small fixes in version mappings.

## 10.2.1

2022-08-23
Expand Down
2 changes: 1 addition & 1 deletion tf/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from zipfile import ZIP_DEFLATED


VERSION = '10.2.3'
VERSION = '10.2.4'
"""Program version.
This value is under control of the update process, as run by
Expand Down

0 comments on commit 958f894

Please sign in to comment.