Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added a Triple Store based on Nodes that fit to the new storage classes. Added also a first Vocabulary for the node store - Dublin Core.
Michael Peter Christen136b514f526f
diff --git a/source/net/yacy/cora/lod/Node.java b/source/net/yacy/cora/lod/Node.javanew file mode 100644index 000000000..2de6fe11e--- /dev/null+++ b/source/net/yacy/cora/lod/Node.java@@ -0,0 +1,75 @@+package net.yacy.cora.lod;++import java.util.Map;+import java.util.HashMap;++import net.yacy.cora.document.UTF8;+import net.yacy.cora.lod.vocabulary.Vocabulary;++public class Node extends HashMap<String, byte[]> implements Map<String, byte[]> {++ private static final long serialVersionUID = -6715118942251224832L;++ public static final String SUBJECT = "rdf:about";++ public Node() {+ super();+ }++ public Node(byte[] subject) {+ super();+ this.put(SUBJECT, subject);+ }++ /**+ * initialize the triples.+ * one of the properties must be the resource SUBJECT+ * for a blank node the SUBJECT can be omitted+ * @param set+ */+ public Node(Map<String, byte[]> set) {+ super();+ this.putAll(set);+ }++ public boolean isBlank() {+ return !this.containsKey(SUBJECT);+ }++ public byte[] getSubject() {+ return this.get(SUBJECT);+ }++ public void setSubject(byte[] subject) {+ this.put(SUBJECT, subject);+ }++ public byte[] getObject(Vocabulary predicate) {+ return this.get(predicate.getPredicate());+ }++ public byte[] setObject(Vocabulary predicate, byte[] object) {+ return this.put(predicate.getPredicate(), object);+ }++ public byte[] removePredicate(Vocabulary predicate) {+ return this.remove(predicate.getPredicate());+ }++ public byte[] toObject() {+ StringBuilder sb = new StringBuilder(this.size() * 50);+ sb.append("<rdf:Description");+ byte[] subject = this.get(SUBJECT);+ if (subject != null) sb.append(" rdf:about=\"").append(UTF8.String(subject)).append('\"');+ sb.append(">\n");+ for (Map.Entry<String, byte[]> entry: this.entrySet()) {+ if (entry.getKey().equals(SUBJECT)) continue;+ sb.append('<').append(entry.getKey()).append('>');+ sb.append(UTF8.String(entry.getValue()));+ sb.append("</").append(entry.getKey()).append(">\n");+ }+ sb.append("</rdf:Description>\n");+ return UTF8.getBytes(sb);+ }++}diff --git a/source/net/yacy/cora/lod/TripleStore.java b/source/net/yacy/cora/lod/TripleStore.javanew file mode 100644index 000000000..8c39307ed--- /dev/null+++ b/source/net/yacy/cora/lod/TripleStore.java@@ -0,0 +1,98 @@+package net.yacy.cora.lod;++import java.util.AbstractMap;+import java.util.Iterator;+import java.util.Map;++import net.yacy.kelondro.blob.MapStore;+import net.yacy.kelondro.order.ByteOrder;+import net.yacy.kelondro.order.CloneableIterator;++public class TripleStore {++ MapStore store;++ public TripleStore(MapStore store) {+ this.store = store;+ }++ public void clear() {+ this.store.clear();+ }++ public boolean contains(byte[] id) {+ return this.store.containsKey(id);+ }++ public Node get(byte[] id) {+ Map<String, byte[]> n = this.store.get(id);+ if (n == null) return null;+ return new Node(n);+ }++ public boolean isEmpty() {+ return this.store.isEmpty();+ }++ public Node put(byte[] id, Node node) {+ Map<String, byte[]> n = this.store.put(id, node);+ if (n == null) return null;+ return new Node(n);+ }++ public void putAll(TripleStore entries) {+ Iterator<Map.Entry<byte[], Node>> i = entries.iterator();+ Map.Entry<? extends byte[], ? extends Node> entry;+ while (i.hasNext()) {+ entry = i.next();+ this.put(entry.getKey(), entry.getValue());+ }+ }++ public Node remove(byte[] id) {+ Map<String, byte[]> n = this.store.remove(id);+ if (n == null) return null;+ return new Node(n);+ }++ public int size() {+ return this.store.size();+ }++ public Iterator<java.util.Map.Entry<byte[], Node>> iterator() {+ final Iterator<byte[]> id = this.idIterator();+ return new Iterator<Map.Entry<byte[], Node>>(){++ @Override+ public boolean hasNext() {+ return id.hasNext();+ }++ @Override+ public Map.Entry<byte[], Node> next() {+ byte[] key = id.next();+ if (key == null) return null;+ return new AbstractMap.SimpleImmutableEntry<byte[], Node>(key, TripleStore.this.get(key));+ }++ @Override+ public void remove() {+ id.remove();+ }++ };+ }++ public ByteOrder getOrdering() {+ return store.getOrdering();+ }++ public CloneableIterator<byte[]> idIterator() {+ return this.store.keyIterator();+ }++ public void close() {+ this.store.close();+ }++}diff --git a/source/net/yacy/cora/lod/vocabulary/DublinCore.java b/source/net/yacy/cora/lod/vocabulary/DublinCore.javanew file mode 100644index 000000000..c67aa6acd--- /dev/null+++ b/source/net/yacy/cora/lod/vocabulary/DublinCore.java@@ -0,0 +1,44 @@+package net.yacy.cora.lod.vocabulary;++public enum DublinCore implements Vocabulary {++ Contributor,+ Coverage,+ Creator,+ Date,+ Description,+ Format,+ Identifier,+ Language,+ Publisher,+ Relation,+ Rights,+ Source,+ Subject,+ Title,+ Type;++ public final static String IDENTIFIER = "http://dublincore.org/documents/2010/10/11/dces/";+ public final static String PREFIX = "dc";++ private final String predicate;++ private DublinCore() {+ this.predicate = PREFIX + ":" + this.name().toLowerCase();+ }++ @Override+ public String getIdentifier() {+ return IDENTIFIER;+ }++ @Override+ public String getPrefix() {+ return PREFIX;+ }++ @Override+ public String getPredicate() {+ return this.predicate;+ }+}diff --git a/source/net/yacy/cora/lod/vocabulary/Vocabulary.java b/source/net/yacy/cora/lod/vocabulary/Vocabulary.javanew file mode 100644index 000000000..a2e7671d4--- /dev/null+++ b/source/net/yacy/cora/lod/vocabulary/Vocabulary.java@@ -0,0 +1,11 @@+package net.yacy.cora.lod.vocabulary;++public interface Vocabulary {++ public String getIdentifier();++ public String getPrefix();++ public String getPredicate();++}