String[] tokens = uri.substring("http://".length()).split("/");
for(String token : tokens) {
identity = findExternalWithNameAndParent(tg, identity.resource, token);
+ if (identity == null) {
+ return null;
+ }
}
return identity;
return result;
}
+ /**
+ * This implementation is no longer advised to use because it returns 0 as
+ * NOT_FOUND which is in fact a valid ID for resource in graph
+ */
+ @Deprecated
public static int getPossibleObject(TransferableGraph1 tg, int subject, Identity predicate) {
int result = 0;
for(int i=0;i<tg.statements.length;i+=4) {
if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
- if(result != 0) return 0;
+ if(result != 0 && tg.statements[i+3] != result) return 0;
result = tg.statements[i+3];
}
}
return result;
}
+
+ public static final int NOT_FOUND = -2;
+
+ public static int getPossibleObject2(TransferableGraph1 tg, int subject, Identity predicate) {
+ int result = NOT_FOUND;
+ for(int i=0;i<tg.statements.length;i+=4) {
+ if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
+ if(result != NOT_FOUND && tg.statements[i+3] != result)
+ return NOT_FOUND;
+ result = tg.statements[i+3];
+ }
+ }
+ return result;
+ }
+ /**
+ * @return 0 for presenting not found which is BAD
+ * @see getPossibleObject2
+ */
+ @Deprecated
public static int getPossibleObject(TransferableGraph1 tg, Identity subject, String predicate) {
Identity p = findExternal(tg, predicate);
if(p == null) return 0;
return getPossibleObject(tg, subject.resource, p);
}
+
+ public static int getPossibleObject2(TransferableGraph1 tg, Identity subject, String predicate) {
+ Identity p = findExternal(tg, predicate);
+ if (p == null)
+ return NOT_FOUND;
+ return getPossibleObject2(tg, subject.resource, p);
+ }
public static Map<Identity, String> getNames(TransferableGraph1 tg, Collection<Identity> ids) {
Map<Identity, String> result = new HashMap<Identity, String>();
if(definition instanceof External) {
External def = (External)definition;
if(def.parent == -1) return "http:/";
- else return getURI(resourceCount, identities, def.parent) + "/" + def.name;
- } else if(definition instanceof Root) {
- Root def = (Root)definition;
- if(def.name.isEmpty()) return "http:/";
- return def.name;
- } else if (definition instanceof Internal) {
- Internal def = (Internal)definition;
- return getURI(resourceCount, identities, def.parent) + "/" + def.name;
- } else {
- return "";
- }
- }
- return "<internal reference " + id + ">:";
- }
-
- public static String getTrueURI(int resourceCount, TIntObjectMap<Identity> identities, int id) {
- Identity identity = identities.get(id);
- if(identity != null) {
- IdentityDefinition definition = identity.definition;
- if(definition instanceof External) {
- External def = (External)definition;
- if(def.parent == -1) return "http:/";
- else return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+ else return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
} else if(definition instanceof Root) {
Root def = (Root)definition;
if(def.name.isEmpty()) return "http:/";
return def.name;
} else if (definition instanceof Internal) {
Internal def = (Internal)definition;
- return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+ return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
} else {
return "";
}