Adds triples to an ontology object.

        Currently assumes gocam/lego-style
352636
def add_triples(self, ontol):
        
        rg = self.rdfgraph
        g = ontol.get_graph()
        typemap = {}
        inds = rg.subjects(RDF.type, OWL.NamedIndividual)
        for s in inds:
            for (s,p,o) in rg.triples((s,None,None)):
                s_id = id(s)
                p_id = id(p)
                g.add_node(s_id)
                if isinstance(o,URIRef):
                    o_id = id(o)
                    if p == RDF.type:
                        if o != OWL.NamedIndividual:
                            if s_id not in typemap:
                                typemap[s_id] = []
                            typemap[s_id].append(o_id)
                    else:
                        g.add_edge(o_id,s_id,pred=p_id)

        # propagate label from type
        for s in typemap.keys():
            g.nodes[s]['types'] = typemap[s]
            if self.tbox_ontology is not None:
                if 'label' not in g.nodes[s]:
                    g.nodes[s]['label'] = ";".join([self.tbox_ontology.label(x) for x in typemap[s] if self.tbox_ontology.label(x) is not None])
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))
1151810
def insertOntology(self, ontology):
        
        try:
            models.Ontology.create(
                    id=ontology.getName(),
                    name=ontology.getName(),
                    dataurl=ontology.getDataUrl(),
                    ontologyprefix=ontology.getOntologyPrefix())
        except Exception:
            raise exceptions.DuplicateNameException(
                ontology.getName())
619026
def visitUnaryShape(self, ctx: ShExDocParser.UnaryShapeContext):
        
        if ctx.include():
            self.expression = self.context.tripleexprlabel_to_iriref(ctx.include().tripleExprLabel())
        else:
            lbl = self.context.tripleexprlabel_to_iriref(ctx.tripleExprLabel()) if ctx.tripleExprLabel() else None
            if ctx.tripleConstraint():
                self.expression = TripleConstraint(lbl)
                self.visit(ctx.tripleConstraint())
            elif ctx.encapsulatedShape():
                self.visit(ctx.encapsulatedShape())
                self.expression.id = lbl
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
831538
def _detailTuples(self, uriRefs):
        
        details = []
        for uriRef in uriRefs:
            for subject, predicate, object_ in self._rdfGraph.triples(
                    (uriRef, None, None)):
                details.append({
                    'subject': subject.toPython(),
                    'predicate': predicate.toPython(),
                    'object': object_.toPython()
                })
        return details
218261
def add(self, t: RDFTriple) -> None:
        
        if self.chained_hook is not None:
            self.chained_hook.add(t)
714983
void triangulateStereoEdges(Motion edge ) {
		View viewA = edge.viewSrc;
		View viewB = edge.viewDst;

		triangulationError.configure(viewA.camera.pinhole,viewB.camera.pinhole);

		for (int i = 0; i < edge.associated.size(); i++) {
			AssociatedIndex f = edge.associated.get(i);

			Point2D_F64 normA = viewA.observationNorm.get(f.src);
			Point2D_F64 normB = viewB.observationNorm.get(f.dst);

			double angle = triangulationAngle(normA,normB,edge.a_to_b);
			if( angle < TRIANGULATE_MIN_ANGLE )
				continue;

			Feature3D feature3D = new Feature3D();

			if( !triangulate.triangulate(normA,normB,edge.a_to_b,feature3D.worldPt) ) {
				continue;
			}

			// must be in front of the camera
			if( feature3D.worldPt.z <= 0 )
				continue;

			// can't have an excessively large reprojection error either
			double error = triangulationError.process(normA,normB,edge.a_to_b,feature3D.worldPt);
			if( error > maxPixelError*maxPixelError )
				continue;

			feature3D.views.add(viewA);
			feature3D.views.add(viewB);
			feature3D.obsIdx.add(f.src);
			feature3D.obsIdx.add(f.dst);
			feature3D.triangulationAngle = angle;

			edge.stereoTriangulations.add(feature3D);
		}
	}
1061523
def triple_in_shape(expr: ShExJ.shapeExpr, label: ShExJ.tripleExprLabel, cntxt: Context) \
        -> Optional[ShExJ.tripleExpr]:
    
    te = None
    if isinstance(expr, (ShExJ.ShapeOr, ShExJ.ShapeAnd)):
        for expr2 in expr.shapeExprs:
            te = triple_in_shape(expr2, label, cntxt)
            if te is not None:
                break
    elif isinstance(expr, ShExJ.ShapeNot):
        te = triple_in_shape(expr.shapeExpr, label, cntxt)
    elif isinstance(expr, ShExJ.shapeExprLabel):
        se = reference_of(expr, cntxt)
        if se is not None:
            te = triple_in_shape(se, label, cntxt)
    return te
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)
        );
    }
1112162
protected function installOntology()
	{
	    helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::MEDIUM);
	    $rdf = ModelManager::getModel()->getRdfInterface();
	    foreach ($this->getExtensionModel() as $triple) {
	        $rdf->add($triple);
	    }
	    helpers_TimeOutHelper::reset();
	}
853752
def _extend_module_definitions(self, graph):
        
        for mod_id in self._modules:
            mod_identity = self._get_triplet_value(graph, URIRef(mod_id), SBOL.module)
            modules = []
            for mod in graph.triples((mod_identity, SBOL.module, None)):
                md = self._get_rdf_identified(graph, mod[2])
                definition_id = self._get_triplet_value(graph, mod[2], SBOL.definition)
                md['definition'] = self._modules[definition_id]
                maps_to = []
                for m in graph.triples((mod[2], SBOL.mapsTo, None)):
                    mt = self._get_rdf_identified(graph, m[2])
                    mt['refinement'] = self._get_triplet_value(graph, m[2], SBOL.refinement)
                    local_id = self._get_triplet_value(graph, m[2], SBOL.local)
                    remote_id = self._get_triplet_value(graph, m[2], SBOL.remote)
                    mt['local'] = self._functional_component_store[local_id]
                    mt['remote'] = self._functional_component_store[remote_id]
                    maps_to.append(MapsTo(**mt))
                modules.append(Module(maps_to=maps_to, **md))
            self._modules[mod_id].modules = modules
255598
def createNewTriples(Win):
    """"""

    win.help("Building list of exposures to look for triples")

    cols=('e.expnum', 'object',
      'mjdate',
      'uttime',
      'elongation',
      'filter',
      'obs_iq_refccd','qso_status' )
    header='%6s %-10s%-12s%10s%10s%10s%8s%10s' %  cols  


    pointings=getNewTriples()
    num_p=len(pointings)

    for pointing in pointings:
        pid=pointing[0]
	mjd=pointing[1]
        expnums=getExpnums(pointing=pid,night=mjd)
        num_p=num_p-1
        while (1):
            ### Loop over this pointing until keystroke gets us out

            win.help("Select (space)  members of triplets - %d remaining" % num_p )

            ## start with an empty list
            explist=[]
            choices=[]

            current_date=''
            for expnum in expnums:
                info=getExpInfo(expnum[0])
                row=()
                if not str(info['triple'])=='None' :
                       continue
                if str(info['obs_iq_refccd'])=='None':
                    info['obs_iq_refccd']=-1.0

                choices.append('%6d %10s %15s %10s %8.2f %10s %8.2f %10s' % (
                    int(info['e.expnum']),
                    str(info['object']),
                    str(info['mjdate']),
                    str(info['uttime']),
                    float(str(info['elongation'])),
                    str(info['filter']),
                    float(str(info['obs_iq_refccd'])),
                    str(info['qso_status'])
                    ))
                explist.append(expnum[0])

            if len(choices)<3:
                ### we need to provide at least 3 choices,
                ### otherwise this isn't a triple (is it)
                break

            ### win.list returns the user's choices as a list.
            choice_list=win.list(header,choices)

            ### zero length list implies were done.
            if choice_list==None:
                break

            ### is this actually a triple?
            if len(choice_list)!=3:
                win.help("Must have 3 members to make a tripple")
                continue

            ### Create a new line in the triple table
            sql = "INSERT INTO triples (id, pointing ) VALUES ( NULL, %s ) "
            cfeps.execute(sql, ( pid, ) )
	    sql = "SELECT id FROM triples WHERE pointing=%s order by id desc" 
	    cfeps.execute(sql, ( pid, ) )
	    ttt=cfeps.fetchall()
            triple= ttt[0][0]
	    win.help(str(triple))

            ### record the members of this new triple.
            sql = "INSERT INTO triple_members (triple, expnum) VALUES ( %s, %s)";
	    win.help(sql)

            for exp in choice_list:
                cfeps.execute(sql,(triple,explist[exp]))

    return(0)
641054
def ontologyPropTree(self):
        
        treedict = {}
        if self.all_properties:
            treedict[0] = self.toplayer_properties
            for element in self.all_properties:
                if element.children():
                    treedict[element] = element.children()
            return treedict
        return treedict
592335
def triple_reference_of(label: ShExJ.tripleExprLabel, cntxt: Context) -> Optional[ShExJ.tripleExpr]:
    
    te: Optional[ShExJ.tripleExpr] = None
    if cntxt.schema.start is not None:
        te = triple_in_shape(cntxt.schema.start, label, cntxt)
    if te is None:
        for shapeExpr in cntxt.schema.shapes:
            te = triple_in_shape(shapeExpr, label, cntxt)
            if te:
                break
    return te
1350368
def skos_hierarchical(rdf, narrower=True):
    
    if narrower:
        for s, o in rdf.subject_objects(SKOS.broader):
            rdf.add((o, SKOS.narrower, s))
    for s, o in rdf.subject_objects(SKOS.narrower):
        rdf.add((o, SKOS.broader, s))
        if not narrower:
            rdf.remove((s, SKOS.narrower, o))
322075
def triple(subject, relation, obj):
    """"""
    return And([Group(subject)(SUBJECT), relation(RELATION), Group(obj)(OBJECT)])