You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Benson Margulies <bi...@gmail.com> on 2014/06/27 15:25:47 UTC
TDB versus an OntModel
here's a little test method. The second call to smallAssertions sees
no triples at all. There's a todo on the doc for ontologies, and I'll
cheerfully write some doc if someone will tell me what dumb thing I've
missed here.
@Test
public void tdb() throws Exception {
Dataset dataset =
TDBFactory.createDataset(tempDataset.getAbsolutePath());
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
OntModel ontModel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
ResTsvReader reader = new ResTsvReader();
URL dataUrl = Resources.getResource(ResTsvReaderTest.class, "data.txt");
ByteSource dataSource = Resources.asByteSource(dataUrl);
reader.read(dataSource, resRdfBuilder);
smallAssertions(ontModel);
dataset.end();
dataset.begin(ReadWrite.READ);
model = dataset.getDefaultModel();
smallAssertions(model);
dataset.end();
}
Re: TDB versus an OntModel
Posted by Benson Margulies <bi...@gmail.com>.
On Mon, Jun 30, 2014 at 1:59 PM, Andy Seaborne <an...@apache.org> wrote:
> connected
Thanks. So, if I want to 'commit every so often', I need to pass the
dataset around. Thanks.
Re: TDB versus an OntModel
Posted by Andy Seaborne <an...@apache.org>.
On 30/06/14 18:21, Benson Margulies wrote:
> Thanks. Does committing the ontModel do any good, or does it have to
> be the dataset?
It has to be the dataset.
(READ transactions can just .end() -- but then commit() or abort() are
the same)
The model transaction operations aren't connected to the database ones;
either we need to change the Model.begin to include READ/WRITE, add
promotable transaction to TDB (with the possibility of system induced
aborts) or make model transactions always write transactions. Each
choice has + and - aspects
Andy
>
> On Mon, Jun 30, 2014 at 11:35 AM, Andy Seaborne <an...@apache.org> wrote:
>> Benson,
>>
>> The example has
>> dataset.begin(ReadWrite.WRITE);
>> ...
>> dataset.end();
>>
>> and it generates a warning. For once, warnings matter!
>>
>> There is no commit.
>>
>> The idiom is:
>>
>> dataset.begin(ReadWrite.WRITE);
>> try {
>>
>> dataset.commit() ;
>> } finally { dataset.end() ; }
>>
>>
>> .end without .commit forces an abort, hence no data in the read transaction.
>>
>> Andy
>>
>>
>> On 29/06/14 15:27, Benson Margulies wrote:
>>>
>>> OK, the default branch (andy) is now buildable outside our office.
>>>
>>> On Sun, Jun 29, 2014 at 10:21 AM, Benson Margulies
>>> <bi...@gmail.com> wrote:
>>>>
>>>> I will build you a test case, but for now, those two classes amount to
>>>> 10 calls to the following, where 'model' is the ontModel.
>>>>
>>>> My premise was that this was a stupid mistake.
>>>>
>>>> Actually, all this code is stuff I can share on github, come to think
>>>> it is, and it's quite small.
>>>>
>>>> https://github.com/benson-basis/tdb-case ... but it wants a parent POM
>>>> that you won't have. Gimme a few minutes ...
>>>>
>>>>
>>>> Individual entity = model.createIndividual(encodedUri("E",
>>>> item.getEntityId()), Res20140626.Entity);
>>>> Individual document = model.createIndividual(encodedUri("D",
>>>> item.getDocId()), Res20140626.Document);
>>>> // anonymous!
>>>> Individual mention =
>>>> model.createIndividual(Res20140626.Mention);
>>>> if (item.getEntityId().startsWith("Q")) {
>>>> model.createStatement(entity, OWL.sameAs,
>>>> String.format("http://www.wikidata.org/entity/%s",
>>>> item.getEntityId()));
>>>> }
>>>>
>>>> model.add(entity, Res20140626.hasEntityMention, mention);
>>>> model.add(mention, Res20140626.hasMentionEntity, entity);
>>>> model.add(mention, Res20140626.hasMentionDocument, document);
>>>> model.add(document, Res20140626.hasDocumentMention, mention);
>>>> if (typedLiterals) {
>>>> model.add(entity, Skos.notation,
>>>> model.createTypedLiteral(item.getEntityId()));
>>>> model.add(document, Skos.notation,
>>>> model.createTypedLiteral(item.getDocId()));
>>>> model.add(mention, Res20140626.hasIndocId,
>>>> model.createTypedLiteral(item.getIndocId()));
>>>> model.add(mention, Res20140626.hasMentionStart,
>>>> model.createTypedLiteral dataset.begin(ReadWrite.WRITE);
>>
>> Model model = dataset.getDefaultModel();
>> OntModel ontModel =
>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>> ResTsvReader reader = new ResTsvReader();
>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>> "data.txt");
>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>> reader.read(dataSource, resRdfBuilder);
>> smallAssertions(ontModel);
>> dataset.end();(item.getMentionStart()));
>>
>>>> model.add(mention, Res20140626.hasMentionEnd,
>>>> model.createTypedLiteral(item.getMentionEnd()));
>>>> model.add(mention, Res20140626.hasMentionText,
>>>> model.createTypedLiteral(item.getMentionText()));
>>>> model.add(mention, Res20140626.hasConfidence,
>>>> model.createTypedLiteral(item.getConfidence()));
>>>> } else {
>>>> model.add(entity, Skos.notation,
>>>> model.createLiteral(item.getEntityId()));
>>>> model.add(document, Skos.notation,
>>>> model.createLiteral(item.getDocId()));
>>>> model.add(mention, Res20140626.hasIndocId,
>>>> model.createLiteral(item.getIndocId()));
>>>> model.add(mention, Res20140626.hasMentionStart,
>>>> model.createLiteral(Integer.toString(item.getMentionStart())));
>>>> model.add(mention, Res20140626.hasMentionEnd,
>>>> model.createLiteral(Integer.toString(item.getMentionEnd())));
>>>> model.add(mention, Res20140626.hasMentionText,
>>>> model.createLiteral(item.getMentionText()));
>>>> model.add(mention, Res20140626.hasConfidence,
>>>> model.createLiteral(Double.toString(item.getConfidence())));
>>>> }
>>>>
>>>> On Sun, Jun 29, 2014 at 6:20 AM, Andy Seaborne <an...@apache.org> wrote:
>>>>>
>>>>> On 27/06/14 14:25, Benson Margulies wrote:
>>>>>>
>>>>>>
>>>>>> here's a little test method. The second call to smallAssertions sees
>>>>>> no triples at all. There's a todo on the doc for ontologies, and I'll
>>>>>> cheerfully write some doc if someone will tell me what dumb thing I've
>>>>>> missed here.
>>>>>>
>>>>>>
>>>>>
>>>>> Hi Benson,
>>>>>
>>>>> There seem to be details that might matter but aren't included. Do you
>>>>> have
>>>>> a complete, standalone, test case?
>>>>>
>>>>>
>>>>>> @Test
>>>>>> public void tdb() throws Exception {
>>>>>> Dataset dataset =
>>>>>> TDBFactory.createDataset(tempDataset.getAbsolutePath());
>>>>>> dataset.begin(ReadWrite.WRITE);
>>>>>> Model model = dataset.getDefaultModel();
>>>>>> OntModel ontModel =
>>>>>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>>>>>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>>>>>> ResTsvReader reader = new ResTsvReader();
>>>>>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>>>>>> "data.txt");
>>>>>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>>>>>> reader.read(dataSource, resRdfBuilder);
>>>>>
>>>>>
>>>>>
>>>>> ResRdfBuilder and ResTsvReader.read -- what do they do?
>>>>>
>>>>>
>>>>>> smallAssertions(ontModel);
>>>>>> dataset.end();
>>>>>>
>>>>>> dataset.begin(ReadWrite.READ);
>>>>>> model = dataset.getDefaultModel();
>>>>>> smallAssertions(model);
>>>>>> dataset.end();
>>>>>> }
>>>>>>
>>>>>
>>>>> Andy
>>>>>
>>
Re: TDB versus an OntModel
Posted by Benson Margulies <bi...@gmail.com>.
Thanks. Does committing the ontModel do any good, or does it have to
be the dataset?
On Mon, Jun 30, 2014 at 11:35 AM, Andy Seaborne <an...@apache.org> wrote:
> Benson,
>
> The example has
> dataset.begin(ReadWrite.WRITE);
> ...
> dataset.end();
>
> and it generates a warning. For once, warnings matter!
>
> There is no commit.
>
> The idiom is:
>
> dataset.begin(ReadWrite.WRITE);
> try {
>
> dataset.commit() ;
> } finally { dataset.end() ; }
>
>
> .end without .commit forces an abort, hence no data in the read transaction.
>
> Andy
>
>
> On 29/06/14 15:27, Benson Margulies wrote:
>>
>> OK, the default branch (andy) is now buildable outside our office.
>>
>> On Sun, Jun 29, 2014 at 10:21 AM, Benson Margulies
>> <bi...@gmail.com> wrote:
>>>
>>> I will build you a test case, but for now, those two classes amount to
>>> 10 calls to the following, where 'model' is the ontModel.
>>>
>>> My premise was that this was a stupid mistake.
>>>
>>> Actually, all this code is stuff I can share on github, come to think
>>> it is, and it's quite small.
>>>
>>> https://github.com/benson-basis/tdb-case ... but it wants a parent POM
>>> that you won't have. Gimme a few minutes ...
>>>
>>>
>>> Individual entity = model.createIndividual(encodedUri("E",
>>> item.getEntityId()), Res20140626.Entity);
>>> Individual document = model.createIndividual(encodedUri("D",
>>> item.getDocId()), Res20140626.Document);
>>> // anonymous!
>>> Individual mention =
>>> model.createIndividual(Res20140626.Mention);
>>> if (item.getEntityId().startsWith("Q")) {
>>> model.createStatement(entity, OWL.sameAs,
>>> String.format("http://www.wikidata.org/entity/%s",
>>> item.getEntityId()));
>>> }
>>>
>>> model.add(entity, Res20140626.hasEntityMention, mention);
>>> model.add(mention, Res20140626.hasMentionEntity, entity);
>>> model.add(mention, Res20140626.hasMentionDocument, document);
>>> model.add(document, Res20140626.hasDocumentMention, mention);
>>> if (typedLiterals) {
>>> model.add(entity, Skos.notation,
>>> model.createTypedLiteral(item.getEntityId()));
>>> model.add(document, Skos.notation,
>>> model.createTypedLiteral(item.getDocId()));
>>> model.add(mention, Res20140626.hasIndocId,
>>> model.createTypedLiteral(item.getIndocId()));
>>> model.add(mention, Res20140626.hasMentionStart,
>>> model.createTypedLiteral dataset.begin(ReadWrite.WRITE);
>
> Model model = dataset.getDefaultModel();
> OntModel ontModel =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
> ResTsvReader reader = new ResTsvReader();
> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
> "data.txt");
> ByteSource dataSource = Resources.asByteSource(dataUrl);
> reader.read(dataSource, resRdfBuilder);
> smallAssertions(ontModel);
> dataset.end();(item.getMentionStart()));
>
>>> model.add(mention, Res20140626.hasMentionEnd,
>>> model.createTypedLiteral(item.getMentionEnd()));
>>> model.add(mention, Res20140626.hasMentionText,
>>> model.createTypedLiteral(item.getMentionText()));
>>> model.add(mention, Res20140626.hasConfidence,
>>> model.createTypedLiteral(item.getConfidence()));
>>> } else {
>>> model.add(entity, Skos.notation,
>>> model.createLiteral(item.getEntityId()));
>>> model.add(document, Skos.notation,
>>> model.createLiteral(item.getDocId()));
>>> model.add(mention, Res20140626.hasIndocId,
>>> model.createLiteral(item.getIndocId()));
>>> model.add(mention, Res20140626.hasMentionStart,
>>> model.createLiteral(Integer.toString(item.getMentionStart())));
>>> model.add(mention, Res20140626.hasMentionEnd,
>>> model.createLiteral(Integer.toString(item.getMentionEnd())));
>>> model.add(mention, Res20140626.hasMentionText,
>>> model.createLiteral(item.getMentionText()));
>>> model.add(mention, Res20140626.hasConfidence,
>>> model.createLiteral(Double.toString(item.getConfidence())));
>>> }
>>>
>>> On Sun, Jun 29, 2014 at 6:20 AM, Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>> On 27/06/14 14:25, Benson Margulies wrote:
>>>>>
>>>>>
>>>>> here's a little test method. The second call to smallAssertions sees
>>>>> no triples at all. There's a todo on the doc for ontologies, and I'll
>>>>> cheerfully write some doc if someone will tell me what dumb thing I've
>>>>> missed here.
>>>>>
>>>>>
>>>>
>>>> Hi Benson,
>>>>
>>>> There seem to be details that might matter but aren't included. Do you
>>>> have
>>>> a complete, standalone, test case?
>>>>
>>>>
>>>>> @Test
>>>>> public void tdb() throws Exception {
>>>>> Dataset dataset =
>>>>> TDBFactory.createDataset(tempDataset.getAbsolutePath());
>>>>> dataset.begin(ReadWrite.WRITE);
>>>>> Model model = dataset.getDefaultModel();
>>>>> OntModel ontModel =
>>>>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>>>>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>>>>> ResTsvReader reader = new ResTsvReader();
>>>>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>>>>> "data.txt");
>>>>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>>>>> reader.read(dataSource, resRdfBuilder);
>>>>
>>>>
>>>>
>>>> ResRdfBuilder and ResTsvReader.read -- what do they do?
>>>>
>>>>
>>>>> smallAssertions(ontModel);
>>>>> dataset.end();
>>>>>
>>>>> dataset.begin(ReadWrite.READ);
>>>>> model = dataset.getDefaultModel();
>>>>> smallAssertions(model);
>>>>> dataset.end();
>>>>> }
>>>>>
>>>>
>>>> Andy
>>>>
>
Re: TDB versus an OntModel
Posted by Andy Seaborne <an...@apache.org>.
Benson,
The example has
dataset.begin(ReadWrite.WRITE);
...
dataset.end();
and it generates a warning. For once, warnings matter!
There is no commit.
The idiom is:
dataset.begin(ReadWrite.WRITE);
try {
dataset.commit() ;
} finally { dataset.end() ; }
.end without .commit forces an abort, hence no data in the read transaction.
Andy
On 29/06/14 15:27, Benson Margulies wrote:
> OK, the default branch (andy) is now buildable outside our office.
>
> On Sun, Jun 29, 2014 at 10:21 AM, Benson Margulies
> <bi...@gmail.com> wrote:
>> I will build you a test case, but for now, those two classes amount to
>> 10 calls to the following, where 'model' is the ontModel.
>>
>> My premise was that this was a stupid mistake.
>>
>> Actually, all this code is stuff I can share on github, come to think
>> it is, and it's quite small.
>>
>> https://github.com/benson-basis/tdb-case ... but it wants a parent POM
>> that you won't have. Gimme a few minutes ...
>>
>>
>> Individual entity = model.createIndividual(encodedUri("E",
>> item.getEntityId()), Res20140626.Entity);
>> Individual document = model.createIndividual(encodedUri("D",
>> item.getDocId()), Res20140626.Document);
>> // anonymous!
>> Individual mention = model.createIndividual(Res20140626.Mention);
>> if (item.getEntityId().startsWith("Q")) {
>> model.createStatement(entity, OWL.sameAs,
>> String.format("http://www.wikidata.org/entity/%s",
>> item.getEntityId()));
>> }
>>
>> model.add(entity, Res20140626.hasEntityMention, mention);
>> model.add(mention, Res20140626.hasMentionEntity, entity);
>> model.add(mention, Res20140626.hasMentionDocument, document);
>> model.add(document, Res20140626.hasDocumentMention, mention);
>> if (typedLiterals) {
>> model.add(entity, Skos.notation,
>> model.createTypedLiteral(item.getEntityId()));
>> model.add(document, Skos.notation,
>> model.createTypedLiteral(item.getDocId()));
>> model.add(mention, Res20140626.hasIndocId,
>> model.createTypedLiteral(item.getIndocId()));
>> model.add(mention, Res20140626.hasMentionStart,
>> model.createTypedLiteral dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
OntModel ontModel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
ResTsvReader reader = new ResTsvReader();
URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
"data.txt");
ByteSource dataSource = Resources.asByteSource(dataUrl);
reader.read(dataSource, resRdfBuilder);
smallAssertions(ontModel);
dataset.end();(item.getMentionStart()));
>> model.add(mention, Res20140626.hasMentionEnd,
>> model.createTypedLiteral(item.getMentionEnd()));
>> model.add(mention, Res20140626.hasMentionText,
>> model.createTypedLiteral(item.getMentionText()));
>> model.add(mention, Res20140626.hasConfidence,
>> model.createTypedLiteral(item.getConfidence()));
>> } else {
>> model.add(entity, Skos.notation,
>> model.createLiteral(item.getEntityId()));
>> model.add(document, Skos.notation,
>> model.createLiteral(item.getDocId()));
>> model.add(mention, Res20140626.hasIndocId,
>> model.createLiteral(item.getIndocId()));
>> model.add(mention, Res20140626.hasMentionStart,
>> model.createLiteral(Integer.toString(item.getMentionStart())));
>> model.add(mention, Res20140626.hasMentionEnd,
>> model.createLiteral(Integer.toString(item.getMentionEnd())));
>> model.add(mention, Res20140626.hasMentionText,
>> model.createLiteral(item.getMentionText()));
>> model.add(mention, Res20140626.hasConfidence,
>> model.createLiteral(Double.toString(item.getConfidence())));
>> }
>>
>> On Sun, Jun 29, 2014 at 6:20 AM, Andy Seaborne <an...@apache.org> wrote:
>>> On 27/06/14 14:25, Benson Margulies wrote:
>>>>
>>>> here's a little test method. The second call to smallAssertions sees
>>>> no triples at all. There's a todo on the doc for ontologies, and I'll
>>>> cheerfully write some doc if someone will tell me what dumb thing I've
>>>> missed here.
>>>>
>>>>
>>>
>>> Hi Benson,
>>>
>>> There seem to be details that might matter but aren't included. Do you have
>>> a complete, standalone, test case?
>>>
>>>
>>>> @Test
>>>> public void tdb() throws Exception {
>>>> Dataset dataset =
>>>> TDBFactory.createDataset(tempDataset.getAbsolutePath());
>>>> dataset.begin(ReadWrite.WRITE);
>>>> Model model = dataset.getDefaultModel();
>>>> OntModel ontModel =
>>>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>>>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>>>> ResTsvReader reader = new ResTsvReader();
>>>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>>>> "data.txt");
>>>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>>>> reader.read(dataSource, resRdfBuilder);
>>>
>>>
>>> ResRdfBuilder and ResTsvReader.read -- what do they do?
>>>
>>>
>>>> smallAssertions(ontModel);
>>>> dataset.end();
>>>>
>>>> dataset.begin(ReadWrite.READ);
>>>> model = dataset.getDefaultModel();
>>>> smallAssertions(model);
>>>> dataset.end();
>>>> }
>>>>
>>>
>>> Andy
>>>
Re: TDB versus an OntModel
Posted by Benson Margulies <bi...@gmail.com>.
OK, the default branch (andy) is now buildable outside our office.
On Sun, Jun 29, 2014 at 10:21 AM, Benson Margulies
<bi...@gmail.com> wrote:
> I will build you a test case, but for now, those two classes amount to
> 10 calls to the following, where 'model' is the ontModel.
>
> My premise was that this was a stupid mistake.
>
> Actually, all this code is stuff I can share on github, come to think
> it is, and it's quite small.
>
> https://github.com/benson-basis/tdb-case ... but it wants a parent POM
> that you won't have. Gimme a few minutes ...
>
>
> Individual entity = model.createIndividual(encodedUri("E",
> item.getEntityId()), Res20140626.Entity);
> Individual document = model.createIndividual(encodedUri("D",
> item.getDocId()), Res20140626.Document);
> // anonymous!
> Individual mention = model.createIndividual(Res20140626.Mention);
> if (item.getEntityId().startsWith("Q")) {
> model.createStatement(entity, OWL.sameAs,
> String.format("http://www.wikidata.org/entity/%s",
> item.getEntityId()));
> }
>
> model.add(entity, Res20140626.hasEntityMention, mention);
> model.add(mention, Res20140626.hasMentionEntity, entity);
> model.add(mention, Res20140626.hasMentionDocument, document);
> model.add(document, Res20140626.hasDocumentMention, mention);
> if (typedLiterals) {
> model.add(entity, Skos.notation,
> model.createTypedLiteral(item.getEntityId()));
> model.add(document, Skos.notation,
> model.createTypedLiteral(item.getDocId()));
> model.add(mention, Res20140626.hasIndocId,
> model.createTypedLiteral(item.getIndocId()));
> model.add(mention, Res20140626.hasMentionStart,
> model.createTypedLiteral(item.getMentionStart()));
> model.add(mention, Res20140626.hasMentionEnd,
> model.createTypedLiteral(item.getMentionEnd()));
> model.add(mention, Res20140626.hasMentionText,
> model.createTypedLiteral(item.getMentionText()));
> model.add(mention, Res20140626.hasConfidence,
> model.createTypedLiteral(item.getConfidence()));
> } else {
> model.add(entity, Skos.notation,
> model.createLiteral(item.getEntityId()));
> model.add(document, Skos.notation,
> model.createLiteral(item.getDocId()));
> model.add(mention, Res20140626.hasIndocId,
> model.createLiteral(item.getIndocId()));
> model.add(mention, Res20140626.hasMentionStart,
> model.createLiteral(Integer.toString(item.getMentionStart())));
> model.add(mention, Res20140626.hasMentionEnd,
> model.createLiteral(Integer.toString(item.getMentionEnd())));
> model.add(mention, Res20140626.hasMentionText,
> model.createLiteral(item.getMentionText()));
> model.add(mention, Res20140626.hasConfidence,
> model.createLiteral(Double.toString(item.getConfidence())));
> }
>
> On Sun, Jun 29, 2014 at 6:20 AM, Andy Seaborne <an...@apache.org> wrote:
>> On 27/06/14 14:25, Benson Margulies wrote:
>>>
>>> here's a little test method. The second call to smallAssertions sees
>>> no triples at all. There's a todo on the doc for ontologies, and I'll
>>> cheerfully write some doc if someone will tell me what dumb thing I've
>>> missed here.
>>>
>>>
>>
>> Hi Benson,
>>
>> There seem to be details that might matter but aren't included. Do you have
>> a complete, standalone, test case?
>>
>>
>>> @Test
>>> public void tdb() throws Exception {
>>> Dataset dataset =
>>> TDBFactory.createDataset(tempDataset.getAbsolutePath());
>>> dataset.begin(ReadWrite.WRITE);
>>> Model model = dataset.getDefaultModel();
>>> OntModel ontModel =
>>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>>> ResTsvReader reader = new ResTsvReader();
>>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>>> "data.txt");
>>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>>> reader.read(dataSource, resRdfBuilder);
>>
>>
>> ResRdfBuilder and ResTsvReader.read -- what do they do?
>>
>>
>>> smallAssertions(ontModel);
>>> dataset.end();
>>>
>>> dataset.begin(ReadWrite.READ);
>>> model = dataset.getDefaultModel();
>>> smallAssertions(model);
>>> dataset.end();
>>> }
>>>
>>
>> Andy
>>
Re: TDB versus an OntModel
Posted by Benson Margulies <bi...@gmail.com>.
I will build you a test case, but for now, those two classes amount to
10 calls to the following, where 'model' is the ontModel.
My premise was that this was a stupid mistake.
Actually, all this code is stuff I can share on github, come to think
it is, and it's quite small.
https://github.com/benson-basis/tdb-case ... but it wants a parent POM
that you won't have. Gimme a few minutes ...
Individual entity = model.createIndividual(encodedUri("E",
item.getEntityId()), Res20140626.Entity);
Individual document = model.createIndividual(encodedUri("D",
item.getDocId()), Res20140626.Document);
// anonymous!
Individual mention = model.createIndividual(Res20140626.Mention);
if (item.getEntityId().startsWith("Q")) {
model.createStatement(entity, OWL.sameAs,
String.format("http://www.wikidata.org/entity/%s",
item.getEntityId()));
}
model.add(entity, Res20140626.hasEntityMention, mention);
model.add(mention, Res20140626.hasMentionEntity, entity);
model.add(mention, Res20140626.hasMentionDocument, document);
model.add(document, Res20140626.hasDocumentMention, mention);
if (typedLiterals) {
model.add(entity, Skos.notation,
model.createTypedLiteral(item.getEntityId()));
model.add(document, Skos.notation,
model.createTypedLiteral(item.getDocId()));
model.add(mention, Res20140626.hasIndocId,
model.createTypedLiteral(item.getIndocId()));
model.add(mention, Res20140626.hasMentionStart,
model.createTypedLiteral(item.getMentionStart()));
model.add(mention, Res20140626.hasMentionEnd,
model.createTypedLiteral(item.getMentionEnd()));
model.add(mention, Res20140626.hasMentionText,
model.createTypedLiteral(item.getMentionText()));
model.add(mention, Res20140626.hasConfidence,
model.createTypedLiteral(item.getConfidence()));
} else {
model.add(entity, Skos.notation,
model.createLiteral(item.getEntityId()));
model.add(document, Skos.notation,
model.createLiteral(item.getDocId()));
model.add(mention, Res20140626.hasIndocId,
model.createLiteral(item.getIndocId()));
model.add(mention, Res20140626.hasMentionStart,
model.createLiteral(Integer.toString(item.getMentionStart())));
model.add(mention, Res20140626.hasMentionEnd,
model.createLiteral(Integer.toString(item.getMentionEnd())));
model.add(mention, Res20140626.hasMentionText,
model.createLiteral(item.getMentionText()));
model.add(mention, Res20140626.hasConfidence,
model.createLiteral(Double.toString(item.getConfidence())));
}
On Sun, Jun 29, 2014 at 6:20 AM, Andy Seaborne <an...@apache.org> wrote:
> On 27/06/14 14:25, Benson Margulies wrote:
>>
>> here's a little test method. The second call to smallAssertions sees
>> no triples at all. There's a todo on the doc for ontologies, and I'll
>> cheerfully write some doc if someone will tell me what dumb thing I've
>> missed here.
>>
>>
>
> Hi Benson,
>
> There seem to be details that might matter but aren't included. Do you have
> a complete, standalone, test case?
>
>
>> @Test
>> public void tdb() throws Exception {
>> Dataset dataset =
>> TDBFactory.createDataset(tempDataset.getAbsolutePath());
>> dataset.begin(ReadWrite.WRITE);
>> Model model = dataset.getDefaultModel();
>> OntModel ontModel =
>> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
>> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
>> ResTsvReader reader = new ResTsvReader();
>> URL dataUrl = Resources.getResource(ResTsvReaderTest.class,
>> "data.txt");
>> ByteSource dataSource = Resources.asByteSource(dataUrl);
>> reader.read(dataSource, resRdfBuilder);
>
>
> ResRdfBuilder and ResTsvReader.read -- what do they do?
>
>
>> smallAssertions(ontModel);
>> dataset.end();
>>
>> dataset.begin(ReadWrite.READ);
>> model = dataset.getDefaultModel();
>> smallAssertions(model);
>> dataset.end();
>> }
>>
>
> Andy
>
Re: TDB versus an OntModel
Posted by Andy Seaborne <an...@apache.org>.
On 27/06/14 14:25, Benson Margulies wrote:
> here's a little test method. The second call to smallAssertions sees
> no triples at all. There's a todo on the doc for ontologies, and I'll
> cheerfully write some doc if someone will tell me what dumb thing I've
> missed here.
>
>
Hi Benson,
There seem to be details that might matter but aren't included. Do you
have a complete, standalone, test case?
> @Test
> public void tdb() throws Exception {
> Dataset dataset =
> TDBFactory.createDataset(tempDataset.getAbsolutePath());
> dataset.begin(ReadWrite.WRITE);
> Model model = dataset.getDefaultModel();
> OntModel ontModel =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
> ResRdfBuilder resRdfBuilder = new ResRdfBuilder(ontModel, 1);
> ResTsvReader reader = new ResTsvReader();
> URL dataUrl = Resources.getResource(ResTsvReaderTest.class, "data.txt");
> ByteSource dataSource = Resources.asByteSource(dataUrl);
> reader.read(dataSource, resRdfBuilder);
ResRdfBuilder and ResTsvReader.read -- what do they do?
> smallAssertions(ontModel);
> dataset.end();
>
> dataset.begin(ReadWrite.READ);
> model = dataset.getDefaultModel();
> smallAssertions(model);
> dataset.end();
> }
>
Andy