Build a simple triple in PyParsing that has a ``subject relation object`` format.
322075
def triple(subject, relation, obj):
    """"""
    return And([Group(subject)(SUBJECT), relation(RELATION), Group(obj)(OBJECT)])
1190558
def serialize(self, format="turtle"):
        
        if self.triples:
            if not self.rdfgraph:
                self._buildGraph()
            return self.rdfgraph.serialize(format=format)
        else:
            return None
890178
def triples(self, source=None, relation=None, target=None):
        
        triplematch = lambda t: (
            (source is None or source == t.source) and
            (relation is None or relation == t.relation) and
            (target is None or target == t.target)
        )
        return list(filter(triplematch, self._triples))
1294215
public function bsonizeTriplesAbout($subject,Array $triples,$context=null)
    {
        $context = ($context==null) ? \Tripod\Config::getInstance()->getDefaultContextAlias() : $this->labeller->uri_to_alias($context);
        $graph = new MongoGraph();
        foreach ($triples as $triple)
        {
            $triple = rtrim($triple);

            $parts = preg_split("/\s/",$triple);
            $subject = trim($parts[0],'><');
            $predicate = trim($parts[1],'><');
            $object = $this->extract_object($parts);

            if ($this->isUri($object))
            {
                $graph->add_resource_triple($subject,$predicate,$object);
            }
            else
            {
                $graph->add_literal_triple($subject,$predicate,$object);
            }
        }
        return $graph->to_tripod_array($subject,$context);
    }
482801
def match(self, subject: Expression) -> Iterator[Tuple[Expression, Substitution]]:
        
        return _MatchIter(self, subject)
1144190
def _structure_tuple(self, obj, tup):
        """"""
        tup_params = tup.__args__
        has_ellipsis = tup_params and tup_params[-1] is Ellipsis
        if tup_params is None or (has_ellipsis and tup_params[0] is Any):
            # Just a Tuple. (No generic information.)
            return tuple(obj)
        if has_ellipsis:
            # We're dealing with a homogenous tuple, Tuple[int, ...]
            tup_type = tup_params[0]
            conv = self._structure_func.dispatch(tup_type)
            return tuple(conv(e, tup_type) for e in obj)
        else:
            # We're dealing with a heterogenous tuple.
            return tuple(
                self._structure_func.dispatch(t)(e, t)
                for t, e in zip(tup_params, obj)
            )
800153
def subject(self) -> Optional[UnstructuredHeader]:
        """"""
        try:
            return cast(UnstructuredHeader, self[b'subject'][0])
        except (KeyError, IndexError):
            return None
928808
def associations(self, subject, object=None):
        
        if object is None:
            if self.associations_by_subj is not None:
                return self.associations_by_subj[subject]
            else:
                return []
        else:
            if self.associations_by_subj_obj is not None:
                return self.associations_by_subj_obj[(subject,object)]
            else:
                return []
733941
def add_triple(self, subj, pred, obj):
        '''  '''
        subj_data, pred_data, obj_data = self.are_ilx([subj, pred, obj])
        # RELATIONSHIP PROPERTY
        if subj_data.get('id') and pred_data.get('id') and obj_data.get('id'):
            if pred_data['type'] != 'relationship':
                return self.test_check('Adding a relationship as formate \
                                       "term1_ilx relationship_ilx term2_ilx"')
            return self.add_relationship(term1=subj_data,
                                         relationship=pred_data,
                                         term2=obj_data)
        # ANNOTATION PROPERTY
        elif subj_data.get('id') and pred_data.get('id'):
            if pred_data['type'] != 'annotation':
                return self.test_check('Adding a relationship as formate \
                                       "term_ilx annotation_ilx value"')
            return self.add_annotation(entity=subj_data,
                                       annotation=pred_data,
                                       value=obj)
        # UPDATE ENTITY
        elif subj_data.get('id'):
            data = subj_data
            _pred = self.ttl2sci_map.get(pred)
            if not _pred:
                error = pred + " doesnt not have correct RDF format or It is not an option"
                return self.test_check(error)
            data = self.custom_update(data, _pred, obj)
            if data == 'failed':  # for debugging custom_update
                return data
            data = superclasses_bug_fix(data)
            url_base = self.base_path + 'term/edit/{id}'
            url = url_base.format(id=data['id'])
            return self.post(url, data)
        else:
            return self.test_check('The ILX ID(s) provided do not exist')
201472
def get_predicates(self, subject, object):
        
        for statement in self.spo_search(subject=subject, object=object):
            yield str(statement[1])
165255
def _get_triplet_value(self, graph, identity, rdf_type):
        
        value = graph.value(subject=identity, predicate=rdf_type)
        return value.toPython() if value is not None else value
615514
def transform_relations(rdf, relationmap):
    """"""

    affected_types = (SKOS.Concept, SKOS.Collection,
                      SKOSEXT.DeprecatedConcept)

    props = set()
    for t in affected_types:
        for conc in rdf.subjects(RDF.type, t):
            for p, o in rdf.predicate_objects(conc):
                if isinstance(o, (URIRef, BNode)) \
                   and (p in relationmap or not in_general_ns(p)):
                    props.add(p)

    for p in props:
        if mapping_match(p, relationmap):
            newval = mapping_get(p, relationmap)
            logging.debug("transform relation %s -> %s", p, str(newval))
            replace_predicate(
                rdf, p, newval, subjecttypes=affected_types)
        else:
            logging.info("Don't know what to do with relation %s", p)
850625
def create_from_tuples(self, tuples, **args):
        
        amap = {}
        subject_label_map = {}
        for a in tuples:
            subj = a[0]
            subject_label_map[subj] = a[1]
            if subj not in amap:
                amap[subj] = []
            amap[subj].append(a[2])

        aset = AssociationSet(subject_label_map=subject_label_map, association_map=amap, **args)
        return aset
862755
def delete_triple(self, subject, predicate, object):
        

        def filter_ontid(ontid):
            if ontid.startswith('http://'):
                pass
            elif ontid.prefix == 'ILXTEMP':
                ontid = 'tmp_' + ontid.suffix
            else:
                ontid = 'ilx_' + ontid.suffix
            return ontid

        # this split between annotations and relationships is severely annoying
        # because you have to know before hand which one it is (sigh)
        s = OntId(subject)
        p = OntId(predicate)
        o = self._get_type(object)
        if type(o) == str:
            func = self.ilx_cli.delete_annotation
        elif type(o) == OntId:
            func = self.ilx_cli.delete_relationship
            o = filter_ontid(o)
        else:
            raise TypeError(f'what are you giving me?! {object!r}')

        s = filter_ontid(s)
        p = filter_ontid(p)

        # TODO: check if add_relationship works
        resp = func(s, p, o)
        return resp
1305686
def relations_to(self, target, include_object=False):
        '''  '''
        if include_object:
            _ = self._execute('''
                select name, (select code from objects where id=src) from relations where dst=?
            ''', (self._id_of(target),))
            for i in _:
                yield self.deserialize(i[1]), i[0]
        else:
            _ = self._execute('''
                select distinct name from relations where dst=?
            ''', (self._id_of(target),))
            for i in _:
                yield i[0]
137171
def relations_to(self, target, include_object=False):
        '''  '''
        relations = self._get_item_node(target).incoming
        if include_object:
            for k in relations:
                for v in relations[k]:
                    if hasattr(v, 'obj'): # filter dead links
                        yield v.obj, k
        else:
            yield from relations
1236613
def skos_transitive(rdf, narrower=True):
    """"""
    for conc in rdf.subjects(RDF.type, SKOS.Concept):
        for bt in rdf.transitive_objects(conc, SKOS.broader):
            if bt == conc:
                continue
            rdf.add((conc, SKOS.broaderTransitive, bt))
            if narrower:
                rdf.add((bt, SKOS.narrowerTransitive, conc))