コード例 #1
0
 def get_organization(self, pattern):
     organization = None
     if pattern is not None:
         if "HBP-SP" in pattern:
             address = Address(locality='HBP', country='Europe')
             organization = Organization(pattern, address, None)
         elif pattern == "Blue Brain Project":
             address = Address(locality='Geneva', country='Switzerland')
             organization = Organization("Blue Brain Project", address,
                                         None)
         elif pattern == "Allen Institute":
             address = Address(locality='Seattle', country='United States')
             organization = Organization("Allen Institute", address, None)
         elif pattern in ("KTH-UNIC", "KOKI-UNIC"):
             address = Address(locality='HBP', country='Europe')
             organization = Organization("HBP-SP6", address, None)
         elif pattern == "Destexhe Lab":
             address = Address(locality='Gif-sur-Yvette', country='France')
             organization = Organization("CNRS", address, None)
         elif pattern in ("<<empty>>", "Other"):
             organization = None
         else:
             raise ValueError(
                 "Can't handle this pattern: {}".format(pattern))
     return organization
コード例 #2
0
    def add_organizations_in_KG_database(self):
        address = Address(locality='HBP', country='Europe')
        for sp_num in range(1, 13):
            org = Organization("HBP-SP{}".format(sp_num), address, None)
            org.save(NAR_client)
        addressBBP = Address(locality='Geneva', country='Switzerland')
        BBP = Organization("Blue Brain Project", addressBBP, None)
        BBP.save(NAR_client)

        addressAllen = Address(locality='Seattle', country='United States')
        spAllen = Organization("Allen Institute", addressAllen, None)
        spAllen.save(NAR_client)

        return ''
コード例 #3
0
ファイル: utils.py プロジェクト: teogale/fairgraph
def generate_random_object(cls, all_fields=True):
    attrs = {}
    for field in cls.fields:
        if all_fields or field.required:
            obj_type = field.types[
                0]  # todo: pick randomly if len(field.types) > 1
            if not field.intrinsic:
                value = None
            elif obj_type == basestring:
                value = _random_text()
            elif obj_type == int:
                value = random.randint(1, 10)
            elif obj_type == float:
                value = random.uniform(0, 1000)
            elif issubclass(obj_type, KGObject):
                if obj_type == KGObject:
                    # specific type is not determined
                    # arbitrarily, let's choose minds.Dataset
                    value = MockKGObject(id=random_uuid(),
                                         type=["minds:Dataset"])
                else:
                    value = MockKGObject(id=random_uuid(),
                                         type=getattr(obj_type, "type", None))
            elif obj_type == QuantitativeValue:
                # todo: subclass QV so we can specify the required dimensionality in `fields`
                value = QuantitativeValue(
                    random.uniform(-10, 10),
                    random.choice(list(QuantitativeValue.unit_codes)))
            elif obj_type == QuantitativeValueRange:
                # todo: subclass QVR so we can specify the required dimensionality in `fields`
                min = random.uniform(-10, 10)
                value = QuantitativeValueRange(
                    min, min + random.uniform(1, 10),
                    random.choice(list(QuantitativeValue.unit_codes)))
            elif issubclass(obj_type, OntologyTerm):
                value = obj_type(random.choice(list(obj_type.iri_map)))
            elif obj_type == datetime:
                value = datetime.now()
            elif obj_type == date:
                value = date.today()
            elif obj_type == bool:
                value = random.choice([True, False])
            elif obj_type == Distribution:
                value = Distribution("http://example.com/myfile.txt")
            elif obj_type == Age:
                value = Age(QuantitativeValue(random.randint(7, 150), "days"),
                            "Post-natal")
            elif obj_type == IRI:
                value = "http://example.com/åêïøù"
            elif obj_type == Address:
                value = Address("Paris", "France")
            elif obj_type == dict:
                value = {"a": 1, "b": 2}
            else:
                raise NotImplementedError(str(obj_type))
            attrs[field.name] = value
    return cls(**attrs)
コード例 #4
0
 def test_round_trip(self, kg_client):
     obj1 = Organization(name="NeuroPSI",
                         address=Address(locality="Saclay", country="France"),
                         parent=KGProxy(Organization, "http://fake_uuid_00481be7a1"))
     instance = Instance(Organization.path, obj1._build_data(kg_client), Instance.path)
     instance.data["@id"] = "http://fake_uuid_7bb3c1e78b"
     instance.data["@type"] = Organization.type
     obj2 = Organization.from_kg_instance(instance, kg_client)
     for field in ("name", "address", "parent"):
         assert getattr(obj1, field) == getattr(obj2, field)
コード例 #5
0
 def test_build_data(self, kg_client):
     obj1 = Organization(name="NeuroPSI",
                         address=Address(locality="Saclay", country="France"),
                         parent=KGProxy(Organization, "http://fake_uuid_00481be7a1"))
     expected = {
         "name": "NeuroPSI",
         "address": {
             "@type": "schema:PostalAddress",
             "addressLocality": "Saclay",
             "addressCountry": "France"
         },
         "parentOrganization": {
             "@type": "nsg:Organization",
             "@id": "http://fake_uuid_00481be7a1"
         }
     }
     assert obj1._build_data(kg_client) == expected