当前位置: 首页>>代码示例>>Python>>正文


Python data.StringVariable类代码示例

本文整理汇总了Python中Orange.data.StringVariable的典型用法代码示例。如果您正苦于以下问题:Python StringVariable类的具体用法?Python StringVariable怎么用?Python StringVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StringVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: capture_image

    def capture_image(self):
        cap = self.cap
        for i in range(3):  # Need some warmup time; use the last frame
            success, frame = cap.read()
            if success:
                self.Error.no_webcam.clear()
            else:
                self.Error.no_webcam()
                return

        def normalize(name):
            return ''.join(ch for ch in unicodedata.normalize('NFD', name.replace(' ', '_'))
                           if unicodedata.category(ch) in 'LuLlPcPd')

        timestamp = datetime.now().strftime('%Y%m%d%H%M%S.%f')
        image_title, self.image_title = self.image_title or self.DEFAULT_TITLE, ''
        normed_name = normalize(image_title)

        for image, suffix, output in (
                (frame, '', self.Output.SNAPSHOT),
                (self.clip_aspect_frame(frame), '_aspect', self.Output.SNAPSHOT_ASPECT)):
            path = os.path.join(
                self.IMAGE_DIR, '{normed_name}_{timestamp}{suffix}.png'.format(**locals()))
            cv2.imwrite(path,
                        # imwrite expects original bgr image, so this is reversed
                        self.bgr2rgb(image) if self.avatar_filter else image)

            image_var = StringVariable('image')
            image_var.attributes['type'] = 'image'
            table = Table.from_numpy(Domain([], metas=[StringVariable('name'), image_var]),
                                     np.empty((1, 0)), metas=np.array([[image_title, path]]))
            self.send(output, table)

        self.snapshot_flash = 80
开发者ID:biolab,项目名称:orange3-prototypes,代码行数:34,代码来源:owwebcamcapture.py

示例2: concatenate_data

def concatenate_data(tables, filenames, label):
    domain, xs = domain_union_for_spectra(tables)
    ntables = [(table if isinstance(table, Table) else table[2]).transform(domain)
               for table in tables]
    data = type(ntables[0]).concatenate(ntables, axis=0)
    source_var = StringVariable.make("Filename")
    label_var = StringVariable.make("Label")

    # add other variables
    xs_atts = tuple([ContinuousVariable.make("%f" % f) for f in xs])
    domain = Domain(xs_atts + domain.attributes, domain.class_vars,
                    domain.metas + (source_var, label_var))
    data = data.transform(domain)

    # fill in spectral data
    xs_sind = np.argsort(xs)
    xs_sorted = xs[xs_sind]
    pos = 0
    for table in tables:
        t = table if isinstance(table, Table) else table[2]
        if not isinstance(table, Table):
            indices = xs_sind[np.searchsorted(xs_sorted, table[0])]
            data.X[pos:pos+len(t), indices] = table[1]
        pos += len(t)

    data[:, source_var] = np.array(list(
        chain(*(repeat(fn, len(table))
                for fn, table in zip(filenames, ntables)))
    )).reshape(-1, 1)
    data[:, label_var] = np.array(list(
        chain(*(repeat(label, len(table))
                for fn, table in zip(filenames, ntables)))
    )).reshape(-1, 1)
    return data
开发者ID:stuart-cls,项目名称:orange-infrared,代码行数:34,代码来源:owmultifile.py

示例3: test_nyt_corpus_domain_generation

    def test_nyt_corpus_domain_generation(self):
        corpus = self.nyt.run_query('slovenia')
        meta_vars = [StringVariable.make(field) for field in NYT_TEXT_FIELDS] + \
                    [StringVariable.make('pub_date'), StringVariable.make('country')]

        self.assertEqual(len(meta_vars), len(corpus.domain.metas))
        self.assertEqual(len(corpus.Y), 10)
开发者ID:RachitKansal,项目名称:orange3-text,代码行数:7,代码来源:test_nyt.py

示例4: test_val

    def test_val(self):
        a = StringVariable("a")
        self.assertEqual(a.to_val(None), "")

        self.assertEqual(a.str_val(Unknown), "?")
        self.assertEqual(a.str_val(Value(a, None)), "None")
        self.assertEqual(a.repr_val(Value(a, "foo")), '"foo"')
开发者ID:testmana2,项目名称:orange3,代码行数:7,代码来源:test_variable.py

示例5: test_to_val

    def test_to_val(self):
        string_var = StringVariable("x")
        self.assertEqual(string_var.to_val("foo"), "foo")
        self.assertEqual(string_var.to_val(42), "42")

        cont_var = ContinuousVariable("x")
        self.assertTrue(math.isnan(cont_var.to_val("?")))
        self.assertTrue(math.isnan(Unknown))

        var = Variable("x")
        self.assertEqual(var.to_val("x"), "x")
开发者ID:acopar,项目名称:orange3,代码行数:11,代码来源:test_variable.py

示例6: test_proxy_has_separate_attributes

    def test_proxy_has_separate_attributes(self):
        image = StringVariable("image")
        image1 = image.make_proxy()
        image2 = image1.make_proxy()

        image.attributes["origin"] = "a"
        image1.attributes["origin"] = "b"
        image2.attributes["origin"] = "c"

        self.assertEqual(image.attributes["origin"], "a")
        self.assertEqual(image1.attributes["origin"], "b")
        self.assertEqual(image2.attributes["origin"], "c")
开发者ID:acopar,项目名称:orange3,代码行数:12,代码来源:test_variable.py

示例7: create_domain

def create_domain(at, cl, metas):
    if OR3:
        return Orange.data.Domain(at, cl, metas=metas)
    else:
        domain  = Orange.data.Domain(at, cl)
        if metas:
            if isinstance(metas, dict):
                metas = sorted(metas.items())
            else:
                metas = zip([ StringVariable.new_meta_id() for _ in metas ], metas)
            domain.add_metas(dict((StringVariable.new_meta_id(), ma) for mi, ma in metas))
        return domain
开发者ID:astaric,项目名称:orange-bio,代码行数:12,代码来源:compat.py

示例8: parse_record_json

def parse_record_json(record, includes_metadata):
    """
    Parses the JSON representation of the record returned by the New York Times Article API.
    :param record: The JSON representation of the query's results.
    :param includes_metadata: The flags that determine which fields to include.
    :return: A list of articles parsed into documents and a list of the
        corresponding metadata, joined in a tuple.
    """
    text_fields = ["headline", "lead_paragraph", "snippet", "abstract", "keywords"]

    documents = []
    class_values = []
    meta_vars = [StringVariable.make(field) for field, flag in zip(text_fields, includes_metadata) if flag]
    # Also add pub_date and glocation.
    meta_vars += [StringVariable.make("pub_date"), StringVariable.make("country")]
    metadata = np.empty((0, len(meta_vars)), dtype=object)
    for doc in record["response"]["docs"]:
        string_document = ""
        metas_row = []
        for field, flag in zip(text_fields, includes_metadata):
            if flag and field in doc:
                field_value = ""
                if isinstance(doc[field], dict):
                    field_value = " ".join([val for val in doc[field].values() if val])
                elif isinstance(doc[field], list):
                    field_value = " ".join([kw["value"] for kw in doc[field] if kw])
                else:
                    if doc[field]:
                        field_value = doc[field]
                string_document += field_value
                metas_row.append(field_value)
        # Add the pub_date.
        field_value = ""
        if "pub_date" in doc and doc["pub_date"]:
            field_value = doc["pub_date"]
        metas_row.append(field_value)
        # Add the glocation.
        metas_row.append(",".join([kw["value"] for kw in doc["keywords"] if kw["name"] == "glocations"]))

        # Add the section_name.
        class_val = ""
        if "section_name" in doc and doc["section_name"]:
            class_val = doc["section_name"]

        documents.append(string_document)
        class_values.append(class_val)
        metadata = np.vstack((metadata, np.array(metas_row)))
    return documents, metadata, meta_vars, class_values
开发者ID:kernc,项目名称:orange3-text,代码行数:48,代码来源:nyt.py

示例9: generate_corpus

 def generate_corpus(self, url_list):
     """
     generate new corpus with values requested by user
     :param url_list:
     :return: corpus
     """
     new_table=None
     text_includes_params = [self.includes_article, self.includes_author, self.includes_date,
                              self.includes_title, self.includes_web_url]
     if True not in text_includes_params:
         self.warning(1, "You must select at least one text field.")
         return
     required_text_fields = [incl_field for yes, incl_field in zip(text_includes_params, ARTICLE_TEXT_FIELDS) if yes]
     meta_vars = [StringVariable.make(field) for field in required_text_fields]
     metadata=[]
     for url in url_list:
         info, is_cached =_get_info(url)
         final_fields = [incl_field for yes, incl_field in zip(text_includes_params, info) if yes]
         metadata.append(final_fields)
     metadata = np.array(metadata, dtype=object)
     metas=metadata
     domain = Domain([], class_vars=None, metas=(meta_vars))
     new_table = Corpus(None, None, metadata, domain, meta_vars)
     self.output_corpus=new_table
     self.send("Corpus",self.output_corpus)
开发者ID:cheral,项目名称:orange3-text,代码行数:25,代码来源:owscraper.py

示例10: _corpus_from_records

def _corpus_from_records(records, includes_metadata):
    """Receives PubMed records and transforms them into a corpus.

    Args:
        records (list): A list of PubMed entries.
        includes_metadata (list): A list of text fields to include.

    Returns:
        corpus: The output Corpus.
    """
    meta_values, class_values = _records_to_corpus_entries(
            records,
            includes_metadata=includes_metadata
    )
    meta_vars = []
    for field_name, _ in includes_metadata:
        if field_name == 'pub_date':
            meta_vars.append(TimeVariable(field_name))
        else:
            meta_vars.append(StringVariable.make(field_name))

    class_vars = [
        DiscreteVariable('section_name', values=list(set(class_values)))
    ]
    domain = Domain([], class_vars=class_vars, metas=meta_vars)

    Y = np.array([class_vars[0].to_val(cv) for cv in class_values])[:, None]

    return Corpus(domain=domain, Y=Y, metas=meta_values)
开发者ID:biolab,项目名称:orange3-text,代码行数:29,代码来源:pubmed.py

示例11: _create_corpus

    def _create_corpus(self):
        corpus = None
        names = ["name", "path", "content"]
        data = []
        category_data = []
        text_categories = list(set(t.category for t in self._text_data))
        values = list(set(text_categories))
        category_var = DiscreteVariable.make("category", values=values)
        for textdata in self._text_data:
            data.append(
                [textdata.name,
                 textdata.path,
                 textdata.content]
            )
            category_data.append(category_var.to_val(textdata.category))
        if len(text_categories) > 1:
            category_data = np.array(category_data)
        else:
            category_var = []
            category_data = np.empty((len(data), 0))
        domain = Domain(
            [], category_var, [StringVariable.make(name) for name in names]
        )
        domain["name"].attributes["title"] = True
        data = np.array(data, dtype=object)
        if len(data):
            corpus = Corpus(domain,
                            Y=category_data,
                            metas=data,
                            text_features=[domain.metas[2]])

        return corpus
开发者ID:s-alexey,项目名称:orange3-text,代码行数:32,代码来源:import_documents.py

示例12: create_domain

def create_domain(at, cl, metas):
    if OR3:
        return Orange.data.Domain(at, cl, metas=metas)
    else:
        domain  = Orange.data.Domain(at, cl)
        if metas:
            domain.add_metas(dict((StringVariable.new_meta_id(), ma) for ma in  metas))
        return domain
开发者ID:acopar,项目名称:orange-bio,代码行数:8,代码来源:geo.py

示例13: create_domain

def create_domain(at, cl, metas):
    if OR3:
        return Orange.data.Domain(at, cl, metas=metas)
    else:
        domain  = Orange.data.Domain(at, cl)
        if metas:
            # add metas in the reverse order (because meta ids are always decreasing)
            # this allows us to pass metas in the same order to create_table
            metas = zip([ StringVariable.new_meta_id() for _ in metas ], reversed(metas))
            domain.add_metas(dict(metas))
        return domain
开发者ID:JakaKokosar,项目名称:orange-bio,代码行数:11,代码来源:compat.py

示例14: _generate_corpus

def _generate_corpus(records, required_text_fields):
    """
    Generates a corpus from the input NYT records.
    :param records: The input NYT records.
    :type records: list
    :param required_text_fields: A list of the available NYT text fields.
    :type required_text_fields: list
    :return: :class: `orangecontrib.text.corpus.Corpus`
    """
    metas, class_values = _parse_record_json(records, required_text_fields)
    documents = []
    for doc in metas:
        documents.append(" ".join([d for d in doc if d is not None]).strip())

    # Create domain.
    meta_vars = [StringVariable.make(field) for field in required_text_fields]
    meta_vars += [StringVariable.make("pub_date"), StringVariable.make("country")]
    class_vars = [DiscreteVariable("section_name", values=list(set(class_values)))]
    domain = Domain([], class_vars=class_vars, metas=meta_vars)

    Y = np.array([class_vars[0].to_val(cv) for cv in class_values])[:, None]

    return Corpus(documents, None, Y, metas, domain)
开发者ID:pombredanne,项目名称:orange3-text,代码行数:23,代码来源:nyt.py

示例15: test_domaineditor_makes_variables

    def test_domaineditor_makes_variables(self):
        # Variables created with domain editor should be interchangeable
        # with variables read from file.

        dat = """V0\tV1\nc\td\n\n1.0\t2"""
        v0 = StringVariable.make("V0")
        v1 = ContinuousVariable.make("V1")

        with named_file(dat, suffix=".tab") as filename:
            self.open_dataset(filename)

            model = self.widget.domain_editor.model()
            model.setData(model.createIndex(0, 1), "text", Qt.EditRole)
            model.setData(model.createIndex(1, 1), "numeric", Qt.EditRole)
            self.widget.apply_button.click()

            data = self.get_output(self.widget.Outputs.data)
            self.assertEqual(data.domain["V0"], v0)
            self.assertEqual(data.domain["V1"], v1)
开发者ID:lanzagar,项目名称:orange3,代码行数:19,代码来源:test_owfile.py


注:本文中的Orange.data.StringVariable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。