コード例 #1
0
    def test_multi_input_summary(self):
        class Str(str):
            pass

        @summarize.register(Str)
        def _(s):
            return PartialSummary(str(s), None)

        class TestWidget(OWBaseWidget):
            class Inputs:
                input_a = MultiInput("A", Str)

            @Inputs.input_a
            def set_a(self, index, a):
                pass

            @Inputs.input_a.insert
            def insert_a(self, index, a):
                pass

            @Inputs.input_a.remove
            def remove_a(self, index):
                pass

        w = TestWidget()
        w.insert_a(0, Str("00"))
        w.insert_a(1, Str("11"))
        self.assertSequenceEqual(
            list(w.input_summaries["A"].values()),
            [PartialSummary("00", None),
             PartialSummary("11", None)])
        w.set_a(0, None)
        self.assertSequenceEqual(list(w.input_summaries["A"].values()),
                                 [PartialSummary("11", None)])
        w.set_a(0, Str("00"))
        self.assertSequenceEqual(
            list(w.input_summaries["A"].values()),
            [PartialSummary("00", None),
             PartialSummary("11", None)])
        w.insert_a(1, Str("05"))
        self.assertSequenceEqual(list(w.input_summaries["A"].values()), [
            PartialSummary("00", None),
            PartialSummary("05", None),
            PartialSummary("11", None)
        ])
        w.set_a(1, None)
        w.remove_a(1)
        self.assertSequenceEqual(
            list(w.input_summaries["A"].values()),
            [PartialSummary("00", None),
             PartialSummary("11", None)])
コード例 #2
0
def summarize_(preprocessor: Preprocess):
    if isinstance(preprocessor, PreprocessorList):
        if preprocessor.preprocessors:
            details = "<br/>".join(map(_name_of, preprocessor.preprocessors))
        else:
            details = _nobr(f"{_name_of(preprocessor)} (empty)")
    else:
        details = _name_of(preprocessor)
    return PartialSummary("🄿", details)
コード例 #3
0
def summarize_(attributes):  # pylint: disable=function-redefined
    n = len(attributes)
    if n == 0:
        details = "empty list"
    elif n <= 3:
        details = _nobr(", ".join(var.name for var in attributes))
    else:
        details = _nobr(", ".join(var.name for var in attributes[:2]) +
                        f" and {n - 2} others")
    return PartialSummary(n, details)
コード例 #4
0
ファイル: corpus.py プロジェクト: biolab/orange3-text
 def summarize_(corpus: Corpus) -> PartialSummary:
     """
     Provides automated input and output summaries for Corpus
     """
     table_summary = summarize.dispatch(Table)(corpus)
     extras = ((f"<br/><nobr>Tokens: {sum(map(len, corpus.tokens))}, "
                f"Types: {len(corpus.dictionary)}</nobr>")
               if corpus.has_tokens() else
               "<br/><nobr>Corpus is not preprocessed</nobr>")
     return PartialSummary(table_summary.summary,
                           table_summary.details + extras)
コード例 #5
0
def summarize_(net: Network):
    n = net.number_of_nodes()
    if len(net.edges) == 1:
        nettype = ['Network', 'Directed network'][net.edges[0].directed]
        details = f"<nobr>{nettype} with {n} nodes " \
                  f"and {net.number_of_edges()} edges</nobr>"
    else:
        details = f"<nobr>Network with {n} nodes"
        if net.edges:
            details += " and {len(net.edges)} edge types:</nobr><ul>" + "".join(
                f"<li>{len(edges)} edges, "
                f"{['undirected', 'directed'][edges.directed]}</li>"
                for edges in net.edges)

    return PartialSummary(n, details)
コード例 #6
0
def summarize(_: SignalTypeA):
    return PartialSummary("foo", "bar")
コード例 #7
0
 def summarize_(model: type_):
     return PartialSummary(symbol, _name_of(model))
コード例 #8
0
def summarize_(results: Results):  # pylint: disable=function-redefined
    nmethods, ninstances = results.predicted.shape
    summary = f"{nmethods}×{ninstances}"
    details = f"{nmethods} method{_plural(nmethods)} " \
              f"on {ninstances} test instance{_plural(ninstances)}"
    return PartialSummary(summary, _nobr(details))
コード例 #9
0
def summarize_(matrix: DistMatrix):  # pylint: disable=function-redefined
    n, m = matrix.shape
    return PartialSummary(f"{n}×{m}", _nobr(f"{n}×{m} distance matrix"))
コード例 #10
0
def summarize_(data: Table):
    return PartialSummary(data.approx_len(),
                          format_summary_details(data, format=Qt.RichText))
コード例 #11
0
 def _(s):
     return PartialSummary(str(s), None)