use of org.openrdf.model.Resource in project blueprints by tinkerpop.
the class SailTest method testClear.
@Test
public void testClear() throws Exception {
URI uriA = sail.getValueFactory().createURI("http://example.org/uriA");
URI uriB = sail.getValueFactory().createURI("http://example.org/uriB");
URI uriC = sail.getValueFactory().createURI("http://example.org/uriC");
SailConnection sc = sail.getConnection();
try {
sc.begin();
sc.clear();
assertEquals(0L, sc.size());
sc.addStatement(uriA, uriB, uriC, uriA);
sc.addStatement(uriC, uriA, uriB, uriA);
sc.addStatement(uriB, uriC, uriA, uriA);
assertEquals(3L, sc.size(uriA));
sc.addStatement(uriA, uriB, uriC, uriB);
sc.addStatement(uriB, uriC, uriA, uriB);
assertEquals(2L, sc.size(uriB));
sc.addStatement(uriA, uriB, uriC);
assertEquals(1L, sc.size((Resource) null));
sc.addStatement(uriA, uriB, uriC, uriC);
sc.addStatement(uriB, uriC, uriA, uriC);
sc.addStatement(uriC, uriA, uriB, uriC);
sc.addStatement(uriA, uriB, uriB, uriC);
assertEquals(4L, sc.size(uriC));
assertEquals(10L, sc.size());
sc.clear(uriA, uriC);
assertEquals(1L, sc.size((Resource) null));
assertEquals(0L, sc.size(uriA));
assertEquals(2L, sc.size(uriB));
assertEquals(0L, sc.size(uriC));
assertEquals(3L, sc.size());
sc.clear();
assertEquals(0L, sc.size());
sc.commit();
} finally {
sc.rollback();
sc.close();
}
}
use of org.openrdf.model.Resource in project backstage by zepheira.
the class Database method abbreviateItems.
protected synchronized void abbreviateItems() {
if (_abbreviatedItems) {
return;
}
_abbreviatedItems = true;
getRepository();
SailConnection sc = null;
try {
sc = _sail.getConnection();
} catch (SailException e) {
_logger.error("Failed to open sail connection in order to compute cached information", e);
}
if (sc != null) {
try {
CloseableIteration<? extends Statement, SailException> i;
try {
i = sc.getStatements(null, RDF.TYPE, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to abbreviate items", e);
return;
}
try {
while (i.hasNext()) {
Statement s = i.next();
Resource r = s.getSubject();
if (r instanceof URI) {
getItemId((URI) r, sc);
}
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
} finally {
try {
sc.close();
} catch (SailException e) {
_logger.warn("Failed to close sail connection", e);
}
}
}
}
use of org.openrdf.model.Resource in project vcell by virtualcell.
the class MIRIAMAnnotationViewer method printResourceMappings.
public static String printResourceMappings(VCMetaData metaData) {
StringBuffer strBuffer = new StringBuffer();
strBuffer.append("\n\n ResourceMappings : \n");
Set<Registry.Entry> entrySet = metaData.getRegistry().getAllEntries();
for (Registry.Entry entry : entrySet) {
Resource resource = entry.getResource();
if (resource != null) {
strBuffer.append(resource.stringValue());
Identifiable identifiable = entry.getIdentifiable();
strBuffer.append(" ============= " + metaData.getIdentifiableProvider().getVCID(identifiable).toASCIIString());
strBuffer.append("\n");
}
}
return strBuffer.toString();
}
use of org.openrdf.model.Resource in project vcell by virtualcell.
the class VCMetaDataMiriamManager method addMiriamRefGroup.
public void addMiriamRefGroup(Identifiable identifiable, MIRIAMQualifier miriamQualifier, Set<MiriamResource> miriamResources) throws URNParseFailureException {
Entry entry = vcMetaData.getRegistry().getEntry(identifiable);
Resource resource = entry.getResource();
if (resource == null) {
String newURIString = vcMetaData.getRegistry().generateFreeURI(identifiable);
resource = entry.setURI(vcMetaData.getRdfData(), newURIString);
}
MIRIAMizer miriamizer = new MIRIAMizer();
RefGroup sybilRefGroup = miriamizer.newRefGroup(vcMetaData.getRdfData(), resource, miriamQualifier);
Set<MIRIAMRef> sybilMiriamRefs = new HashSet<MIRIAMRef>();
for (MiriamResource miriamResource : miriamResources) {
sybilMiriamRefs.add(MIRIAMRef.createFromURN(miriamResource.getMiriamURN()));
}
for (MIRIAMRef sybilMiriamRef : sybilMiriamRefs) {
sybilRefGroup.add(vcMetaData.getRdfData(), sybilMiriamRef);
}
invalidateCache(identifiable);
vcMetaData.fireAnnotationEventListener(new VCMetaData.AnnotationEvent(identifiable));
}
use of org.openrdf.model.Resource in project vcell by virtualcell.
the class VCMetaDataMiriamManager method getPrettyName.
public String getPrettyName(MiriamResource miriamResource) {
Resource resource = vcMetaData.getRdfData().getValueFactory().createURI(miriamResource.getMiriamURN());
Iterator<Statement> iter = vcMetaData.getRdfData().match(resource, ProtegeDC.description, null);
while (iter.hasNext()) {
Statement statement = iter.next();
return statement.getObject().toString();
}
return null;
}
Aggregations