diff --git a/htroot/YMarks.java b/htroot/YMarks.java index 193cf6f84..d8d9cbd86 100644 --- a/htroot/YMarks.java +++ b/htroot/YMarks.java @@ -29,18 +29,19 @@ public class YMarks { YMarkRDF rdf = new YMarkRDF("http://"+sb.peers.myAlternativeAddress()); if(post != null && post.containsKey(YMarkEntry.BOOKMARKS_ID)) { - final String id = post.get(YMarkEntry.BOOKMARKS_ID); - final int i = id.indexOf(':'); - final String bmk_user = id.substring(0,i); - final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user); - final byte[] urlHash = UTF8.getBytes(id.substring(i+1, id.length())); - Tables.Row bmk_row; - try { - bmk_row = sb.tables.select(bmk_table, urlHash); - rdf.addBookmark(bmk_user, bmk_row); - } catch (IOException e) { - } catch (SpaceExceededException e) { - } + final String id[] = post.get(YMarkEntry.BOOKMARKS_ID).split(":"); + if(id[1].equals("b")) { + final String bmk_user = id[0]; + final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user); + final byte[] urlHash = UTF8.getBytes(id[2]); + Tables.Row bmk_row; + try { + bmk_row = sb.tables.select(bmk_table, urlHash); + rdf.addBookmark(bmk_user, bmk_row); + } catch (IOException e) { + } catch (SpaceExceededException e) { + } + } } else { final Iterator iter = sb.tables.iterator(); while(iter.hasNext()) { @@ -57,7 +58,7 @@ public class YMarks { } } } - prop.put("rdf", rdf.getRDF("RDF/XML")); + prop.put("rdf", rdf.getRDF("RDF/XML-ABBREV")); return prop; } if(isAdmin || isAuthUser) { diff --git a/source/de/anomic/data/ymark/YMarkRDF.java b/source/de/anomic/data/ymark/YMarkRDF.java index f3bdadb65..79095a06b 100644 --- a/source/de/anomic/data/ymark/YMarkRDF.java +++ b/source/de/anomic/data/ymark/YMarkRDF.java @@ -13,6 +13,7 @@ import net.yacy.cora.lod.vocabulary.DCElements; import net.yacy.cora.lod.vocabulary.Rdf; import net.yacy.kelondro.blob.Tables; +import com.hp.hpl.jena.rdf.model.Bag; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Property; @@ -24,9 +25,11 @@ public class YMarkRDF { public final static String USER = "USER"; public final static String TYPE = "TYPE"; + public final static String SUBTOPIC = "SUBTOPIC"; + private final Map property; - public final static String BOOKMARK = "/Ymarks.rdf?id="; + public final static String BOOKMARK = "/YMarks.rdf?id="; private final StringBuilder resourceURI; private final int len; @@ -54,6 +57,7 @@ public class YMarkRDF { this.property.put(USER, this.model.createProperty(DCElements.creator.getNamespace(), DCElements.creator.name())); this.property.put(TYPE, this.model.createProperty(Rdf.type.getNamespace(), Rdf.type.name())); + this.property.put(SUBTOPIC, this.model.createProperty(AnnoteaB.subTopicOf.getNamespace(), AnnoteaB.subTopicOf.name())); } /** @@ -70,40 +74,83 @@ public class YMarkRDF { } } + public void addTopic(final String bmk_user, final String folder) { + this.resourceURI.append(bmk_user); + this.resourceURI.append(":f:"); + this.resourceURI.append(UTF8.String(YMarkUtil.getKeyId(folder))); + final Resource topic = this.model.createResource(this.resourceURI.toString()); + this.resourceURI.setLength(this.len); + + topic.addProperty(this.property.get(YMarkEntry.BOOKMARK.DATE_MODIFIED.key()), YMarkUtil.EMPTY_STRING); + topic.addProperty(this.property.get(YMarkEntry.BOOKMARK.DATE_ADDED.key()), YMarkUtil.EMPTY_STRING); + topic.addProperty(this.property.get(USER), bmk_user); + topic.addProperty(this.property.get(YMarkEntry.BOOKMARK.DESC.key()), YMarkUtil.EMPTY_STRING); + final int i = folder.lastIndexOf(YMarkUtil.FOLDERS_SEPARATOR); + if(i>0) + topic.addProperty(this.property.get(SUBTOPIC), folder.substring(0, i)); + topic.addProperty(this.property.get(YMarkEntry.BOOKMARK.TITLE.key()), folder); + topic.addProperty(this.property.get(TYPE), AnnoteaB.Topic.getPredicate()); + } + public void addBookmark (final String bmk_user, final Tables.Row bmk_row) { if(bmk_row == null || bmk_row.get(YMarkEntry.BOOKMARK.PUBLIC.key(), YMarkEntry.BOOKMARK.PUBLIC.deflt()).equals("false")) - return; - final Resource bmk; + return; // create an annotea bookmark resource this.resourceURI.append(bmk_user); - this.resourceURI.append(':'); + this.resourceURI.append(":b:"); this.resourceURI.append(UTF8.String(bmk_row.getPK())); - bmk = this.model.createResource(this.resourceURI.toString()); + final Resource bmk = this.model.createResource(this.resourceURI.toString()); this.resourceURI.setLength(this.len); // add properties - bmk.addProperty(this.property.get(TYPE), AnnoteaB.Bookmark.getPredicate()); bmk.addProperty(this.property.get(USER), bmk_user); - for (final YMarkEntry.BOOKMARK b : YMarkEntry.BOOKMARK.values()) { - switch(b) { - case FOLDERS: - final String[] folders = bmk_row.get(b.key(), b.deflt()).split(YMarkUtil.TAGS_SEPARATOR); - for(String folder : folders) { - bmk.addProperty(this.property.get(b.key()), folder); - // TODO add Topics to RDF + for (final YMarkEntry.BOOKMARK b : YMarkEntry.BOOKMARK.values()) { + switch(b) { + case FOLDERS: + final String[] folders = bmk_row.get(b.key(), b.deflt()).split(b.seperator()); + if(folders.length > 1) { + Bag topics = this.model.createBag(); + for(String folder : folders) { + topics.add(folder); + this.addTopic(bmk_user, folder); + } + bmk.addProperty(this.property.get(b.key()), topics); + } else { + bmk.addProperty(this.property.get(b.key()), folders[0]); + this.addTopic(bmk_user, folders[0]); + } + break; + case TAGS: + final String[] tags = bmk_row.get(b.key(), b.deflt()).split(b.seperator()); + if(tags.length > 1) { + Bag subjects = this.model.createBag(); + for(String tag : tags) { + subjects.add(tag); + } + bmk.addProperty(this.property.get(b.key()), subjects); + } else { + bmk.addProperty(this.property.get(b.key()), tags[0]); } break; + case DATE_ADDED: case DATE_MODIFIED: final YMarkDate date = new YMarkDate(bmk_row.get(b.key())); bmk.addProperty(this.property.get(b.key()), date.toISO8601()); break; + // these cases are inserted for better readable RDF output + case DESC: + case URL: + case TITLE: + bmk.addProperty(this.property.get(b.key()), bmk_row.get(b.key(), b.deflt())); + break; default: if(this.property.containsKey(b.key())) { bmk.addProperty(this.property.get(b.key()), bmk_row.get(b.key(), b.deflt())); } } } + bmk.addProperty(this.property.get(TYPE), AnnoteaB.Bookmark.getPredicate()); } public void addBookmarks(final String bmk_user, final Iterator riter) {