You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Lorenz Buehmann <bu...@informatik.uni-leipzig.de> on 2023/01/01 09:22:17 UTC

Re: How to list OntModel Individual OntProperty triples?

Hi Steve!

Looks like you're looking for something similar to 
Individual::getOntClasses, but I think there is no such method in the code.

Also, once getting statements, the type itself would be opaque.

What you can do is to call .canAs() and then .as() methods, for example

OntModel m = ...

ExtendedIterator<Individual> individuals = m.listIndividuals();
individuals.forEach(i -> {
             i.listProperties().forEach(stmt -> {
                 Property predicate = stmt.getPredicate();
                 if (predicate.canAs(OntProperty.class)) {
                     OntProperty property = predicate.as(OntProperty.class);
                 }
             });
         });


But I think this is not what you want, but I can't think of why you 
would need this?


Cheers,

Lorenz

On 31.12.22 17:45, Steve Vestal wrote:
> I am using Individual#listProperties (inherited 
> Resource#listProperties) to get the property instances (triples) for 
> Individuals in an OntModel.  This method returns an iterator of 
> Statements.  The statement objects are returned as ResourceImpl java 
> objects, and the predicates are returned as PropertyImpl java 
> objects.  What I would like to get as statement objects and predicates 
> are the OntResource and OntProperty implementations from the 
> OntModel.  I could find no methods such as Resource#isOntResource or 
> Resource#asOntResource.  What is a good way to list property triples 
> that maintains existing Ontology natures of statement objects, 
> predicates, subjects?
>

Re: Atomic sparql Insert

Posted by Andy Seaborne <an...@apache.org>.
Please don't tag onto an unrelated email thread.

On 03/01/2023 12:49, jaanam@kolumbus.fi wrote:
> Hello, I've about 10 000 variables in my Jena Fuseki v. 3.7.0 database. 

4.7.0 is the latest Jena release.

> All of them created using the INSERT DATA-command below.
> 
> I just noticed that four of those ~10 000 entries are missing the third 
> triplet:
> 
>                      gsimsf:EnumeratedValueDomain\/$TECH_NAME a 
> gsimsf_ont:EnumeratedValueDomain ;
>                                              gsimsf:hasStatId "$STAT_ID" .
> 
> I've been considering INSERT commands as atomic,

They are, and inside a transaction.

What's the storage?

	Andy

> but now it looks like 
> some of them had been disturbed, can it be possible ? And if yes, how 
> can this be fixed ?
> 
> 
> 
> $PREFIXS
> 
>              INSERT DATA
>                  { GRAPH tilasto:$STAT
>                      {
>                      cubemeta:CubeMeta\/$RDF_ID cubemeta:hasVariable 
> gsimsf:Variable\/$TECH_NAME .
> 
>                      gsimsf:Variable\/$TECH_NAME a gsimsf_ont:Variable ;
>                                          rdfs:label "$TITLE_FI"@fi ;
>                                          rdfs:label "$TITLE_SV"@sv ;
>                                          rdfs:label "$TITLE_EN"@en ;
>                                          dc:description "$DESC_FI"@fi ;
>                                          dc:description "$DESC_SV"@sv ;
>                                          dc:description "$DESC_EN"@en ;
>                                          gsimsf:hasEnumeratedValueDomain 
> gsimsf:EnumeratedValueDomain\/$TECH_NAME .
> 
>                      gsimsf:EnumeratedValueDomain\/$TECH_NAME a 
> gsimsf_ont:EnumeratedValueDomain ;
>                                              gsimsf:hasStatId "$STAT_ID" .
> 
>                      pxt:PxDimension\/$RDF_ID\/$TECH_NAME a 
> pxt_ont:PxDimension ;
>                                          pxt:isPresentationOfVariable 
> gsimsf:Variable\/$TECH_NAME ;
>                                          pxt:hasSequenceNumber $NRO;
>                                          pxt:hasVariableType "$VAR_TYPE" ;
>                                          pxt:isHeading 
> "$PX_DEMENTION"^^xsd:boolean ;
>                                          pxt:hasCodedVariable 
> pxt:PxCodedVariable\/$RDF_ID\/$TECH_NAME .
> 
>                      pxt:PxCodedVariable\/$RDF_ID\/$TECH_NAME a 
> pxt_ont:PxCodedVariable ;
>                                          pxt:hasMap "$MAPS" ;
>                                          pxt:hasPxDomain "$DOMAIN" ;
>                                          pxt:hasElimination 
> "$ELIMINATION" ;
>                                          pxt:hasScaleType "$SCALETYPE" ;
>                                          pxt:prependCode 
> "$PREPENDCODE"^^xsd:boolean ;
> pxt:isPresentationOfEnumeratedValueDomain 
> gsimsf:EnumeratedValueDomain\/$TECH_NAME .
> 
>                      pxt:PxFile\/$RDF_ID pxt:hasPxDimension 
> pxt:PxDimension\/$RDF_ID\/$TECH_NAME .
> 
>                      }
>                  }
> 
> Br, Jaana M

Atomic sparql Insert

Posted by ja...@kolumbus.fi.
Hello, I've about 10 000 variables in my Jena Fuseki v. 3.7.0 database. 
All of them created using the INSERT DATA-command below.

I just noticed that four of those ~10 000 entries are missing the third 
triplet:

                     gsimsf:EnumeratedValueDomain\/$TECH_NAME a 
gsimsf_ont:EnumeratedValueDomain ;
                                             gsimsf:hasStatId "$STAT_ID" 
.

I've been considering INSERT commands as atomic, but now it looks like 
some of them had been disturbed, can it be possible ? And if yes, how 
can this be fixed ?



$PREFIXS

             INSERT DATA
                 { GRAPH tilasto:$STAT
                     {
                     cubemeta:CubeMeta\/$RDF_ID cubemeta:hasVariable 
gsimsf:Variable\/$TECH_NAME .

                     gsimsf:Variable\/$TECH_NAME a gsimsf_ont:Variable ;
                                         rdfs:label "$TITLE_FI"@fi ;
                                         rdfs:label "$TITLE_SV"@sv ;
                                         rdfs:label "$TITLE_EN"@en ;
                                         dc:description "$DESC_FI"@fi ;
                                         dc:description "$DESC_SV"@sv ;
                                         dc:description "$DESC_EN"@en ;
                                         gsimsf:hasEnumeratedValueDomain 
gsimsf:EnumeratedValueDomain\/$TECH_NAME .

                     gsimsf:EnumeratedValueDomain\/$TECH_NAME a 
gsimsf_ont:EnumeratedValueDomain ;
                                             gsimsf:hasStatId "$STAT_ID" 
.

                     pxt:PxDimension\/$RDF_ID\/$TECH_NAME a 
pxt_ont:PxDimension ;
                                         pxt:isPresentationOfVariable 
gsimsf:Variable\/$TECH_NAME ;
                                         pxt:hasSequenceNumber $NRO;
                                         pxt:hasVariableType "$VAR_TYPE" 
;
                                         pxt:isHeading 
"$PX_DEMENTION"^^xsd:boolean ;
                                         pxt:hasCodedVariable 
pxt:PxCodedVariable\/$RDF_ID\/$TECH_NAME .

                     pxt:PxCodedVariable\/$RDF_ID\/$TECH_NAME a 
pxt_ont:PxCodedVariable ;
                                         pxt:hasMap "$MAPS" ;
                                         pxt:hasPxDomain "$DOMAIN" ;
                                         pxt:hasElimination 
"$ELIMINATION" ;
                                         pxt:hasScaleType "$SCALETYPE" ;
                                         pxt:prependCode 
"$PREPENDCODE"^^xsd:boolean ;
                                         
pxt:isPresentationOfEnumeratedValueDomain 
gsimsf:EnumeratedValueDomain\/$TECH_NAME .

                     pxt:PxFile\/$RDF_ID pxt:hasPxDimension 
pxt:PxDimension\/$RDF_ID\/$TECH_NAME .

                     }
                 }

Br, Jaana M

Re: How to list OntModel Individual OntProperty triples?

Posted by Steve Vestal <st...@galois.com>.
Thanks again, that worked to fetch statement predicates as both 
OntResource and OntProperty.

This came up while experimenting to better understand rdf-frames (see 
earlier apologetically lengthy Question about RDF Frames). However, this 
might be useful when using SPARQL with OntModels and dealing with 
imports that do not fully conform to OWL (e.g., use vanilla 
rdf:property, which I have seen happen in files that have owl:Ontology 
declarations).

On 1/1/2023 3:22 AM, Lorenz Buehmann wrote:
> Hi Steve!
>
> Looks like you're looking for something similar to 
> Individual::getOntClasses, but I think there is no such method in the 
> code.
>
> Also, once getting statements, the type itself would be opaque.
>
> What you can do is to call .canAs() and then .as() methods, for example
>
> OntModel m = ...
>
> ExtendedIterator<Individual> individuals = m.listIndividuals();
> individuals.forEach(i -> {
>             i.listProperties().forEach(stmt -> {
>                 Property predicate = stmt.getPredicate();
>                 if (predicate.canAs(OntProperty.class)) {
>                     OntProperty property = 
> predicate.as(OntProperty.class);
>                 }
>             });
>         });
>
>
> But I think this is not what you want, but I can't think of why you 
> would need this?
>
>
> Cheers,
>
> Lorenz
>
> On 31.12.22 17:45, Steve Vestal wrote:
>> I am using Individual#listProperties (inherited 
>> Resource#listProperties) to get the property instances (triples) for 
>> Individuals in an OntModel.  This method returns an iterator of 
>> Statements.  The statement objects are returned as ResourceImpl java 
>> objects, and the predicates are returned as PropertyImpl java 
>> objects.  What I would like to get as statement objects and 
>> predicates are the OntResource and OntProperty implementations from 
>> the OntModel.  I could find no methods such as Resource#isOntResource 
>> or Resource#asOntResource.  What is a good way to list property 
>> triples that maintains existing Ontology natures of statement 
>> objects, predicates, subjects?
>>