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


Python fc.FeatureCollection类代码示例

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


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

示例1: test_non_counter_features_bad_serialize

def test_non_counter_features_bad_serialize():
    with pytest.raises(SerializationError):
        FeatureCollection({"NAME": "foobaz"})
    fc = FeatureCollection()
    fc["NAME"] = "foobaz"
    with pytest.raises(SerializationError):
        fc.dumps()
开发者ID:dossier,项目名称:dossier.fc,代码行数:7,代码来源:test_feature_collection.py

示例2: test_nsc_roundtrip

def test_nsc_roundtrip():
    fc = FeatureCollection()
    fc['#testing'] = NestedStringCounter()
    fc['#testing']['foo'] = StringCounter({'foo': 1})
    fc['#testing']['bar'] = StringCounter({'foo': 2, 'bar': 1})
    dumped = fc.dumps()
    assert FeatureCollection.loads(dumped) == fc
开发者ID:dossier,项目名称:dossier.fc,代码行数:7,代码来源:test_nested_stringcounter.py

示例3: test_ft_roundtrip

def test_ft_roundtrip():
    fc = FeatureCollection()
    fc['@NAME']['foo'].append([
        ('nltk', 5, 2),
    ])
    fc2 = FeatureCollection.loads(fc.dumps())
    assert fc['@NAME'] == fc2['@NAME']
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:7,代码来源:test_feature_tokens.py

示例4: test_read_only_preserved_after_serialized

def test_read_only_preserved_after_serialized():
    fc = FeatureCollection({'NAME': {'foo': 1, 'baz': 2}})
    fc.read_only = True
    fcnew = FeatureCollection.loads(fc.dumps())
    assert fcnew.read_only
    with pytest.raises(ReadOnlyException):
        fcnew['NAME']['foo'] += 1
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:7,代码来源:test_read_only.py

示例5: test_readonly

def test_readonly(counter_type):
    fc = FeatureCollection({
            'hello': counter_type(Counter('hello')),
            'goodbye': counter_type(Counter('goodbye'))})
    fc2 = FeatureCollection({
            'hello': counter_type(Counter('hello')),
            'goodbye': counter_type(Counter('goodbye'))})

    fc.read_only = True
    with pytest.raises(ReadOnlyException):
        fc += fc2

    with pytest.raises(ReadOnlyException):
        fc -= fc2

    with pytest.raises(ReadOnlyException):
        fc *= 2

    with pytest.raises(ReadOnlyException):
        fc['woof'] = StringCounter()

    if hasattr(counter_type, 'read_only'):
        with pytest.raises(ReadOnlyException):
            fc['hello']['l'] = 3
        with pytest.raises(ReadOnlyException):
            fc['hello']['l'] += 3

    fc.read_only = False
    fc += fc2
    assert Counter(map(abs,fc['hello'].values())) == Counter({2: 3, 4: 1})
    fc -= fc2
    fc -= fc2
    assert Counter(map(abs,fc['hello'].values())) == Counter()
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:33,代码来源:test_read_only.py

示例6: test_string_counter_serialize

def test_string_counter_serialize():
    fc = FeatureCollection()
    fc['thing1'] = StringCounter()
    fc['thing1']['foo'] += 1
    fc_str = fc.dumps()

    fc2 = FeatureCollection.loads(fc_str)
    assert fc2['thing1']['foo'] == 1
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:8,代码来源:test_serialization.py

示例7: test_serialize_deserialize

def test_serialize_deserialize(counter_type):
    ## build entity, serialize, deserialize, and verify its multisets
    ent1 = FeatureCollection()
    ent1["bow"] += counter_type(Counter(["big", "dog"]))
    ent1["bow"] += counter_type(Counter("tall building"))
    ent1["bon"] += counter_type(Counter(["Super Cat", "Small Cat", "Tiger Fish"]))

    blob = ent1.dumps()
    ent2 = FeatureCollection.loads(blob)
    assert_same_fc(ent1, ent2)
开发者ID:dossier,项目名称:dossier.fc,代码行数:10,代码来源:test_feature_collection.py

示例8: test_read_only_binop

def test_read_only_binop():
    fc1 = FeatureCollection({'NAME': {'foo': 1, 'bar': 1}})
    fc2 = FeatureCollection({'NAME': {'foo': 2, 'bar': 2}})

    fc1.read_only = True
    fc2.read_only = True

    result = fc1 + fc2
    expected = FeatureCollection({'NAME': {'foo': 3, 'bar': 3}})
    assert result == expected
    assert not result.read_only
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:11,代码来源:test_read_only.py

示例9: test_read_only_features

def test_read_only_features():
    fc = FeatureCollection({'feat': StringCounter({'foo': 1})})
    fc['feat']['foo'] += 1
    fc.read_only = True

    with pytest.raises(ReadOnlyException):
        fc['feat']['foo'] += 1
    with pytest.raises(ReadOnlyException):
        fc['feat'].pop('foo')
    with pytest.raises(ReadOnlyException):
        del fc['feat']['foo']
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:11,代码来源:test_read_only.py

示例10: test_serialize_deserialize

def test_serialize_deserialize(counter_type):
    ## build entity, serialize, deserialize, and verify its multisets
    ent1 = FeatureCollection()
    ent1['bow'] += counter_type(Counter(['big', 'dog']))
    ent1['bow'] += counter_type(Counter('tall building'))
    ent1['bon'] += counter_type(Counter(['Super Cat', 'Small Cat',
                                         'Tiger Fish']))

    blob = ent1.dumps()
    ent2 = FeatureCollection.loads(blob)
    assert_same_fc(ent1, ent2)
开发者ID:brianolson,项目名称:dossier.fc,代码行数:11,代码来源:test_feature_collection.py

示例11: test_json_serializer

def test_json_serializer():
    with registry:
        registry.add('StringCounter', JsonSerializer)

        fc = FeatureCollection()
        fc['thing2'] = StringCounter(dict(hello='people'))
        fc['thing2']['another'] = 5
        fc['thing3'] = StringCounter(dict(hello='people2'))
        fc_str = fc.dumps()

        fc2 = FeatureCollection.loads(fc_str)

        assert fc2['thing2']['another'] == 5
        assert fc2['thing2']['hello'] == 'people'
        assert fc2['thing3']['hello'] == 'people2'
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:15,代码来源:test_serialization.py

示例12: test_thing_serializer

def test_thing_serializer():
    with registry:
        registry.add('StringCounter', ThingSerializer)

        fc = FeatureCollection()
        fc['thing1'] = Thing(json.dumps(dict(hello='people')))
        fc['thing1']['another'] = 'more'
        fc['thing1'].do_more_things()
        fc_str = fc.dumps()

        fc2 = FeatureCollection.loads(fc_str)

        assert fc2['thing1']['another'] == 'more'
        assert fc2['thing1']['hello'] == 'people'
        assert fc2['thing1']['doing'] == 'something'
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:15,代码来源:test_serialization.py

示例13: perftest_throughput_feature_collection

def perftest_throughput_feature_collection():
    with registry:
        registry.add('StringCounter', ThingSerializer)
        fc = FeatureCollection()
        fc['thing1'] = Thing(json.dumps(dict(one_mb=' ' * 2**20)))
        fc_str = fc.dumps()

        start_time = time.time()
        num = 1000
        for i in range(num):
            fc2 = FeatureCollection.loads(fc_str)
            fc2.dumps()
        elapsed = time.time() - start_time
        rate = float(num) / elapsed
        print('%d MB in %.1f sec --> %.1f MB per sec' % (num, elapsed, rate))
开发者ID:brandontheis,项目名称:dossier.fc,代码行数:15,代码来源:performance.py

示例14: test_multiset_change

def test_multiset_change(counter_type):
    ent1 = FeatureCollection()
    ent1['bow'] += counter_type(Counter(['big', 'dog']))
    ent1.pop('bow')
    assert dict(ent1.items()) == dict()

    ## can pop empty -- fails
    #ent1.pop('foo')

    ## set equal to
    test_data = ['big2', 'dog2']
    ent1['bow'] = counter_type(Counter(test_data))
    assert list(ent1['bow'].values()) == [1,1]

    ent1['bow'] += counter_type(Counter(test_data))
    assert list(ent1['bow'].values()) == [2,2]
开发者ID:brianolson,项目名称:dossier.fc,代码行数:16,代码来源:test_feature_collection.py

示例15: test_multiset_change

def test_multiset_change(counter_type):
    ent1 = FeatureCollection()
    ent1["bow"] += counter_type(Counter(["big", "dog"]))
    ent1.pop("bow")
    assert dict(ent1.items()) == dict()

    ## can pop empty -- fails
    # ent1.pop('foo')

    ## set equal to
    test_data = ["big2", "dog2"]
    ent1["bow"] = counter_type(Counter(test_data))
    assert list(map(abs, ent1["bow"].values())) == [1, 1]

    ent1["bow"] += counter_type(Counter(test_data))
    assert list(map(abs, ent1["bow"].values())) == [2, 2]
开发者ID:dossier,项目名称:dossier.fc,代码行数:16,代码来源:test_feature_collection.py


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