Return Concept from an Eidos entity.
482464
def get_concept(entity):
        """"""
        # Use the canonical name as the name of the Concept
        name = entity['canonicalName']
        db_refs = EidosProcessor.get_groundings(entity)
        concept = Concept(name, db_refs=db_refs)
        return concept
407472
def setup_concept_scheme(rdf, defaultcs):
    """"""
    for conc in rdf.subjects(RDF.type, SKOS.Concept):
        # check concept scheme
        cs = rdf.value(conc, SKOS.inScheme, None, any=True)
        if cs is None:  # need to set inScheme
            rdf.add((conc, SKOS.inScheme, defaultcs))
591917
def from_dict(cls, d):
        
        if "ICOHP" in d:
            icohp = {Spin(int(key)): np.array(val)
                     for key, val in d["ICOHP"].items()}
        else:
            icohp = None
        return Cohp(d["efermi"], d["energies"],
                    {Spin(int(key)): np.array(val)
                     for key, val in d["COHP"].items()},
                    icohp=icohp, are_coops=d["are_coops"])
667077
def eidos_process_jsonld():
    """"""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    eidos_json = body.get('jsonld')
    ep = eidos.process_json_str(eidos_json)
    return _stmts_from_proc(ep)
1232170
def add_concept(self, concept_obj):
        '''  '''
        if concept_obj is None:
            raise Exception("Concept object cannot be None")
        elif concept_obj in self.__concepts:
            raise Exception("Concept object is already inside")
        elif concept_obj.cidx in self.__concept_map:
            raise Exception("Duplicated concept ID ({})".format(concept_obj.cidx))
        self.__concepts.append(concept_obj)
        self.__concept_map[concept_obj.cidx] = concept_obj
        concept_obj.sent = self
        return concept_obj
91455
def _from_dict(cls, _dict):
        """"""
        args = {}
        xtra = _dict.copy()
        if 'entity' in _dict:
            args['entity'] = _dict.get('entity')
            del xtra['entity']
        else:
            raise ValueError(
                'Required property \'entity\' not present in RuntimeEntity JSON'
            )
        if 'location' in _dict:
            args['location'] = _dict.get('location')
            del xtra['location']
        else:
            raise ValueError(
                'Required property \'location\' not present in RuntimeEntity JSON'
            )
        if 'value' in _dict:
            args['value'] = _dict.get('value')
            del xtra['value']
        else:
            raise ValueError(
                'Required property \'value\' not present in RuntimeEntity JSON')
        if 'confidence' in _dict:
            args['confidence'] = _dict.get('confidence')
            del xtra['confidence']
        if 'metadata' in _dict:
            args['metadata'] = _dict.get('metadata')
            del xtra['metadata']
        if 'groups' in _dict:
            args['groups'] = [
                CaptureGroup._from_dict(x) for x in (_dict.get('groups'))
            ]
            del xtra['groups']
        args.update(xtra)
        return cls(**args)
588095
def get_repository(self, entity_cls):
        """"""
        model_cls = self.get_model(entity_cls)
        return DictRepository(self, entity_cls, model_cls)
24598
def get_entity(self, entity_id, at=None):
        

        # Get a snapshot (None if none exist).
        if self._snapshot_strategy is not None:
            snapshot = self._snapshot_strategy.get_snapshot(entity_id, lte=at)
        else:
            snapshot = None

        # Decide the initial state of the entity, and the
        # version of the last item applied to the entity.
        if snapshot is None:
            initial_state = None
            gt = None
        else:
            initial_state = entity_from_snapshot(snapshot)
            gt = snapshot.originator_version

        # Obtain and return current state.
        return self.get_and_project_events(entity_id, gt=gt, lte=at, initial_state=initial_state)
95894
def from_dict(cls, entity_cls, adict):
        """"""
        invalid_req = InvalidRequestObject()

        # Extract the pagination parameters from the input
        page = int(adict.pop('page', 1))
        per_page = int(adict.pop(
            'per_page', getattr(active_config, 'PER_PAGE', 10)))
        order_by = adict.pop('order_by', ())

        # Check for invalid request conditions
        if page < 0:
            invalid_req.add_error('page', 'is invalid')

        if invalid_req.has_errors:
            return invalid_req

        # Do we need to pop out random?
        # adict.pop('random', None)

        return cls(entity_cls, page, per_page, order_by, adict)
799970
def from_mongo(cls, doc):
		""""""
		
		if doc is None:  # To support simplified iterative use, None should return None.
			return None
		
		if isinstance(doc, Document):  # No need to perform processing on existing Document instances.
			return doc
		
		if cls.__type_store__ and cls.__type_store__ in doc:  # Instantiate specific class mentioned in the data.
			cls = load(doc[cls.__type_store__], 'marrow.mongo.document')
		
		# Prepare a new instance in such a way that changes to the instance will be reflected in the originating doc.
		instance = cls(_prepare_defaults=False)  # Construct an instance, but delay default value processing.
		instance.__data__ = doc  # I am Popeye of Borg (pattern); you will be askimilgrated.
		instance._prepare_defaults()  # pylint:disable=protected-access -- deferred default value processing.
		
		return instance
505240
def from_id(cls, id):
        """"""
        from furious.context import Context

        # TODO: Handle exceptions and retries here.
        entity = cls.get_by_id(id)
        if not entity:
            raise FuriousContextNotFoundError(
                "Context entity not found for: {}".format(id))

        return Context.from_dict(entity.context)
92176
def _from_pb(cls, pb, set_key=True, ent=None, key=None):
    """"""
    if not isinstance(pb, entity_pb.EntityProto):
      raise TypeError('pb must be a EntityProto; received %r' % pb)
    if ent is None:
      ent = cls()

    # A key passed in overrides a key in the pb.
    if key is None and pb.key().path().element_size():
      key = Key(reference=pb.key())
    # If set_key is not set, skip a trivial incomplete key.
    if key is not None and (set_key or key.id() or key.parent()):
      ent._key = key

    # NOTE(darke): Keep a map from (indexed, property name) to the property.
    # This allows us to skip the (relatively) expensive call to
    # _get_property_for for repeated fields.
    _property_map = {}
    projection = []
    for indexed, plist in ((True, pb.property_list()),
                           (False, pb.raw_property_list())):
      for p in plist:
        if p.meaning() == entity_pb.Property.INDEX_VALUE:
          projection.append(p.name())
        property_map_key = (p.name(), indexed)
        if property_map_key not in _property_map:
          _property_map[property_map_key] = ent._get_property_for(p, indexed)
        _property_map[property_map_key]._deserialize(ent, p)

    ent._set_projection(projection)
    return ent
717236
def from_wc(cls, wc):
        """"""
        return cls(wcdict=wc.dict, scale=wc.scale, eft=wc.eft, basis=wc.basis)
248288
def fetch(cls, id, service=None, endpoint=None, *args, **kwargs):
        """"""
        if service is None and endpoint is None:
            raise InvalidArguments(service, endpoint)

        if endpoint is None:
            sid = service['id'] if isinstance(service, Entity) else service
            endpoint = 'services/{0}/integrations'.format(sid)

        return getattr(Entity, 'fetch').__func__(cls, id, endpoint=endpoint,
                                                 *args, **kwargs)
351959
def get_by_entityid(self, entityid):
		
		data = self.list(entityid=entityid)
		if len(data) == 0:
			return None

		eid = int( next(iter(data)) )
		entity = self.get(eid)

		self.debug(0x01,entity)
		return entity
955146
def conceptscheme_from_uri(conceptscheme_uri, **kwargs):
    '''
    
    '''

    # get the conceptscheme
    # ensure it only ends in one slash
    conceptscheme_uri = conceptscheme_uri.strip('/') + '/'
    s = kwargs.get('session', requests.Session())
    graph = uri_to_graph('%s.rdf' % (conceptscheme_uri), session=s)

    notes = []
    labels = []
    if graph is not False:
        for s, p, o in graph.triples((URIRef(conceptscheme_uri), RDFS.label, None)):
            label = Label(o.toPython(), "prefLabel", 'en')
            labels.append(label)

    conceptscheme = ConceptScheme(
        conceptscheme_uri,
        labels=labels,
        notes=notes
    )
    return conceptscheme
1120445
def get_concept_scheme(rdf):
    
    # add explicit type
    for s, o in rdf.subject_objects(SKOS.inScheme):
        if not isinstance(o, Literal):
            rdf.add((o, RDF.type, SKOS.ConceptScheme))
        else:
            logging.warning(
                "Literal value %s for skos:inScheme detected, ignoring.", o)
    css = list(rdf.subjects(RDF.type, SKOS.ConceptScheme))
    if len(css) > 1:
        css.sort()
        cs = css[0]
        logging.warning(
            "Multiple concept schemes found. "
            "Selecting %s as default concept scheme.", cs)
    elif len(css) == 1:
        cs = css[0]
    else:
        cs = None

    return cs