Prepare a triple for rdflib
357757
def prep(s, p, o):
    '''
    
    '''
    def bnode_check(r):
        return isinstance(r, mock_bnode) or r.startswith('VERSABLANKNODE_')

    s = BNode() if bnode_check(s) else URIRef(s)
    p = URIRef(p)
    o = BNode() if bnode_check(o) else (URIRef(o) if isinstance(o, I) else Literal(o))
    return s, p, o
183611
private void addDCTriples(Datastream ds,
                              URIReference objURI,
                              Set<Triple> set) throws Exception {
        DCFields dc = new DCFields(ds.getContentStream());
        Map<RDFName, List<DCField>> map = dc.getMap();
        for (RDFName predicate : map.keySet()) {
            for (DCField dcField : map.get(predicate)) {
                String lang = dcField.getLang();
                if (lang == null) {
                    add(objURI, predicate, dcField.getValue(), set);
                } else {
                    add(objURI, predicate, dcField.getValue(), lang, set);
                }
            }
        }
    }
604352
def entityTriples(rdfGraph, anEntity, excludeProps=False, excludeBNodes=False,
                  orderProps=[RDF, RDFS, OWL.OWLNS, DC.DCNS]):
    
    temp = []
    if not excludeProps:
        excludeProps = []

    # extract predicate/object
    for x, y, z in rdfGraph.triples((anEntity, None, None)):
        if excludeBNodes and isBlankNode(z):
            continue
        if y not in excludeProps:
            temp += [(y, z)]

    # sorting
    if type(orderProps) == type([]):
        orderedUris = sortByNamespacePrefix([y for y, z in temp], orderProps)  # order props only
        orderedUris = [(n + 1, x) for n, x in
                       enumerate(orderedUris)]  # create form: [(1, 'something'),(2,'bobby'),(3,'suzy'),(4,'crab')]
        rank = dict((key, rank) for (rank, key) in orderedUris)  # create dict to pass to sorted procedure
        temp = sorted(temp, key=lambda tup: rank.get(tup[0]))
    elif orderProps:  # default to alpha sorting unless False
        temp = sorted(temp, key=lambda tup: tup[0])

    # if niceURI:
    #	temp = [(uri2niceString(ontology, y), z) for y,z in temp]

    return temp
1303778
private Triple toTriple(TripleID tripleId) {
        return new Triple(
            dictionary.getNode(tripleId.getSubject(), TripleComponentRole.SUBJECT),
            dictionary.getNode(tripleId.getPredicate(), TripleComponentRole.PREDICATE),
            dictionary.getNode(tripleId.getObject(), TripleComponentRole.OBJECT)
        );
    }
889833
void writeBestRankTriples() {
		for (Resource resource : this.rankBuffer.getBestRankedStatements()) {
			try {
				this.rdfWriter.writeTripleUriObject(resource,
						RdfWriter.RDF_TYPE, RdfWriter.WB_BEST_RANK.toString());
			} catch (RDFHandlerException e) {
				throw new RuntimeException(e.getMessage(), e);
			}
		}
		this.rankBuffer.clear();
	}
718629
function RDFMakeTerm(formula,val, canonicalize) {
	    if (typeof val != 'object') {   
		if (typeof val == 'string')
	            return new N3Parser.Literal(val);
		if (typeof val == 'number')
		    return new N3Parser.Literal(val); // @@ differet types
		if (typeof val == 'boolean')
		    return new N3Parser.Literal(val?"1":"0", undefined, 
					    N3Parser.Symbol.prototype.XSDboolean);
		else if (typeof val == 'number')
	            return new N3Parser.Literal(''+val);   // @@ datatypes
		else if (typeof val == 'undefined')
	            return undefined;
		else    // @@ add converting of dates and numbers
	            throw "Can't make Term from " + val + " of type " + typeof val; 
	    }
	    return val;
	}
621172
def tripleExprFor(self, id_: ShExJ.tripleExprLabel) -> ShExJ.tripleExpr:
        
        return self.te_id_map.get(id_)
439836
def remove_triple(self, p, o, auto_refresh=True):

		'''
		
		'''

		self.rdf.graph.remove((self.uri, p, self._handle_object(o)))

		# determine if triples refreshed
		self._handle_triple_refresh(auto_refresh)
1346476
def triplify_object(binding):
    
    triples = []
    if binding.uri:
        triples.append((binding.subject, RDF.type, binding.uri))

    if binding.parent is not None:
        parent = binding.parent.subject
        if binding.parent.is_array:
            parent = binding.parent.parent.subject
        triples.append((parent, binding.predicate, binding.subject))
        if binding.reverse is not None:
            triples.append((binding.subject, binding.reverse, parent))

    for prop in binding.properties:
        _, prop_triples = triplify(prop)
        triples.extend(prop_triples)

    return binding.subject, triples
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))
1129846
def get_object_format(triple=None):
    
    if triple is None:
        triple = get_default_triple()
    res = ffi.lib.LLVMPY_GetTripleObjectFormat(_encode_string(triple))
    return _object_formats[res]
726442
def rdcandump(filename, count=None,
              is_not_log_file_format=False,
              interface=None):
    
    try:
        if isinstance(filename, six.string_types):
            file = open(filename, "rb")
        else:
            file = filename

        pkts = list()
        ifilter = None
        if interface is not None:
            if isinstance(interface, six.string_types):
                ifilter = [interface]
            else:
                ifilter = interface

        for l in file.readlines():
            if is_not_log_file_format:
                h, data = l.split(b']')
                intf, idn, le = h.split()
                t = None
            else:
                t, intf, f = l.split()
                idn, data = f.split(b'#')
                le = None
                t = float(t[1:-1])

            if ifilter is not None and intf.decode('ASCII') not in ifilter:
                continue

            data = data.replace(b' ', b'')
            data = data.strip()

            pkt = CAN(identifier=int(idn, 16), data=binascii.unhexlify(data))
            if le is not None:
                pkt.length = int(le[1:])
            else:
                pkt.length = len(pkt.data)

            if len(idn) > 3:
                pkt.flags = 0b100

            if t is not None:
                pkt.time = t

            pkts.append(pkt)
            if count is not None and len(pkts) >= count:
                break

    finally:
        file.close()

    return pkts
748887
def load_rdf(self,
                 uri_or_path=None,
                 data=None,
                 file_obj=None,
                 rdf_format="",
                 verbose=False,
                 hide_base_schemas=True,
                 hide_implicit_types=True,
                 hide_implicit_preds=True):
        """"""
        loader = RDFLoader(verbose=verbose)
        loader.load(uri_or_path, data, file_obj, rdf_format)
        self.rdflib_graph = loader.rdflib_graph
        self.sources = loader.sources_valid
        self.sparqlHelper = SparqlHelper(self.rdflib_graph)
        self.namespaces = sorted(self.rdflib_graph.namespaces())
209810
def _get_triplet_value_list(self, graph, identity, rdf_type):
        
        values = []
        for elem in graph.objects(identity, rdf_type):
            values.append(elem.toPython())
        return values
1191301
def displayTriples(triples, qname=qname):
    
    [print(*(e[:5]
             if isinstance(e, rdflib.BNode) else
             qname(e)
             for e in t), '.')
             for t in sorted(triples)]
388519
def execute(self, triple_map, output, **kwargs):
        
        subject = self.generate_term(term_map=triple_map.subjectMap,
                                     **kwargs)
        start_size = len(output)
        all_subjects = []
        for pred_obj_map in triple_map.predicateObjectMap:
            predicate = pred_obj_map.predicate
            if pred_obj_map.template is not None:
                object_ = self.generate_term(term_map=pred_obj_map, **kwargs)
                if len(str(object)) > 0:
                    output.add((
                        subject,
                        predicate,
                        object_))

            if pred_obj_map.parentTriplesMap is not None:
                self.__handle_parents__(
                    parent_map=pred_obj_map.parentTriplesMap,
                    subject=subject,
                    predicate=predicate,
                    **kwargs)
            if pred_obj_map.reference is not None:
                object_ = self.generate_term(term_map=pred_obj_map,
                                             **kwargs)
                if object_ and len(str(object_)) > 0:
                    output.add((subject, predicate, object_))
            if pred_obj_map.constant is not None:
                output.add((subject, predicate, pred_obj_map.constant))
        finish_size = len(output)
        if finish_size > start_size:
            output.add((subject,
                             NS_MGR.rdf.type.rdflib,
                             triple_map.subjectMap.class_))
            all_subjects.append(subject)
        return all_subjects
948673
def _graph_of_triples_from_construct_or_describe(construct_query)
      ntriples_str = Tripod::SparqlClient::Query.query(construct_query, Tripod.ntriples_header_str)
      _rdf_graph_from_ntriples_string(ntriples_str, graph=nil)
    end