You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/02/19 13:52:00 UTC
[20/52] [partial] code contribution,
initial import of relevant modules of LMF-3.0.0-SNAPSHOT based on
revision 4bf944319368 of the default branch at https://code.google.com/p/lmf/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/clients/SearchClient.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/clients/SearchClient.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/clients/SearchClient.java
new file mode 100644
index 0000000..ef6307e
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/clients/SearchClient.java
@@ -0,0 +1,161 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.clients;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.exception.LMFClientException;
+import at.newmedialab.lmf.client.util.KiWiCollections;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Collections2;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.MoreLikeThisParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provide Semantic Search functionality to the LMF search cores based on SOLRJ queries and results. Any SOLRJ query
+ * can be used and a SOLRJ result is returned, so the client provides maximum flexibility.
+ * <p/>
+ * SOLR updating is not supported through this client, since this is not an intended use of the LMF search cores.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class SearchClient {
+
+ private static Logger log = LoggerFactory.getLogger(CoresClient.class);
+
+ private static final String URL_SOLR_SERVICE = "/solr";
+
+ private ClientConfiguration config;
+
+ Set<String> cores;
+
+ public SearchClient(ClientConfiguration config) {
+ this.config = config;
+
+ CoresClient coresClient = new CoresClient(config);
+ cores = new HashSet<String>();
+ try {
+ cores.addAll(coresClient.listCores());
+ } catch (IOException e) {
+ log.error("could not initialise list of cores; search functionality will not work",e);
+ } catch (LMFClientException e) {
+ log.error("could not initialise list of cores; search functionality will not work", e);
+ }
+ }
+
+ /**
+ * Run a SOLR search against the selected core and return the result as SolrDocumentList.
+ *
+ * @param coreName name of the core to query
+ * @param query the SolrQuery to run on the core
+ * @return
+ * @throws IOException
+ * @throws LMFClientException
+ */
+ public SolrDocumentList search(String coreName, SolrQuery query) throws IOException, LMFClientException {
+ Preconditions.checkArgument(cores.contains(coreName),"core {} does not exist",coreName);
+
+ SolrServer server = new HttpSolrServer(config.getLmfUri()+URL_SOLR_SERVICE+"/"+ URLEncoder.encode(coreName,"utf-8"));
+
+ try {
+ QueryResponse response = server.query(query);
+ return response.getResults();
+ } catch (SolrServerException e) {
+ log.error("error while evaluating SOLR query",e);
+ throw new LMFClientException("error while evaluating SOLR query",e);
+ }
+
+ }
+
+
+ /**
+ * Perform a simple string search on the given core using default parameters for the SolrQuery.
+ */
+ public SolrDocumentList simpleSearch(String coreName, String queryString, Map<String,String> options) throws IOException, LMFClientException {
+ SolrQuery query = new SolrQuery();
+ query.setQuery(queryString);
+ if(options != null && options.containsKey("fields")) {
+ query.setFields(options.get("fields"));
+ } else {
+ query.setFields("*,score");
+ }
+
+ if(options != null && options.containsKey("sort")) {
+ query.addSortField(options.get("sort"), SolrQuery.ORDER.desc);
+ } else {
+ query.addSortField("score", SolrQuery.ORDER.desc);
+ }
+
+ if(options != null && options.containsKey("facets")) {
+ for(String facet : options.get("facets").split(",")) {
+ query.addFacetField(facet);
+ }
+ }
+ if(options != null && options.containsKey("offset")) {
+ query.setStart(Integer.parseInt(options.get("offset")));
+ }
+ if(options != null && options.containsKey("limit")) {
+ query.setRows(Integer.parseInt(options.get("limit")));
+ }
+ return search(coreName,query);
+
+ }
+
+
+ /**
+ * Retrieve recommendations for the given URI using the SOLR moreLikeThis handler for the core passed as first argument.
+ * The fieldWeights map field names to weights, where 1 is the standard weight. Can be used to improve the significance of
+ * a field in the calculation of recommendations.
+ *
+ * @param coreName
+ * @param uri
+ * @param fieldWeights
+ * @return
+ * @throws IOException
+ * @throws LMFClientException
+ */
+ public SolrDocumentList recommendations(String coreName, String uri, Map<String,Double> fieldWeights) throws IOException, LMFClientException {
+ SolrQuery query = new SolrQuery();
+ query.setQuery("uri:\""+URLEncoder.encode(uri,"utf-8")+"\"");
+ query.setFields("*,score");
+ query.addSortField("score", SolrQuery.ORDER.desc);
+ query.setQueryType("/" + MoreLikeThisParams.MLT);
+ query.set(MoreLikeThisParams.MATCH_INCLUDE, false);
+ query.set(MoreLikeThisParams.MIN_DOC_FREQ, 1);
+ query.set(MoreLikeThisParams.MIN_TERM_FREQ, 1);
+ query.set(MoreLikeThisParams.SIMILARITY_FIELDS, KiWiCollections.fold(fieldWeights.keySet(),","));
+ query.set(MoreLikeThisParams.QF, KiWiCollections.fold(Collections2.transform(fieldWeights.entrySet(), new Function<Map.Entry<String, Double>, Object>() {
+ @Override
+ public Object apply(Map.Entry<String, Double> input) {
+ return input.getKey()+"^"+input.getValue();
+ }
+ })," "));
+ return search(coreName,query);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ContentFormatException.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ContentFormatException.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ContentFormatException.java
new file mode 100644
index 0000000..8a1d140
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ContentFormatException.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.exception;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ContentFormatException extends LMFClientException {
+
+ /**
+ * Constructs a new exception with <code>null</code> as its detail message.
+ * The cause is not initialized, and may subsequently be initialized by a
+ * call to {@link #initCause}.
+ */
+ public ContentFormatException() {
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message. The
+ * cause is not initialized, and may subsequently be initialized by
+ * a call to {@link #initCause}.
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public ContentFormatException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public ContentFormatException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public ContentFormatException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/LMFClientException.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/LMFClientException.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/LMFClientException.java
new file mode 100644
index 0000000..f9a97ff
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/LMFClientException.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.exception;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LMFClientException extends Exception{
+
+ /**
+ * Constructs a new exception with <code>null</code> as its detail message.
+ * The cause is not initialized, and may subsequently be initialized by a
+ * call to {@link #initCause}.
+ */
+ public LMFClientException() {
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message. The
+ * cause is not initialized, and may subsequently be initialized by
+ * a call to {@link #initCause}.
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public LMFClientException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public LMFClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public LMFClientException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/NotFoundException.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/NotFoundException.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/NotFoundException.java
new file mode 100644
index 0000000..c4cbca6
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/NotFoundException.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.exception;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class NotFoundException extends LMFClientException {
+ /**
+ * Constructs a new exception with <code>null</code> as its detail message.
+ * The cause is not initialized, and may subsequently be initialized by a
+ * call to {@link #initCause}.
+ */
+ public NotFoundException() {
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message. The
+ * cause is not initialized, and may subsequently be initialized by
+ * a call to {@link #initCause}.
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public NotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public NotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public NotFoundException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ParseException.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ParseException.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ParseException.java
new file mode 100644
index 0000000..5039afb
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/exception/ParseException.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.exception;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ParseException extends LMFClientException {
+
+ /**
+ * Constructs a new exception with <code>null</code> as its detail message.
+ * The cause is not initialized, and may subsequently be initialized by a
+ * call to {@link #initCause}.
+ */
+ public ParseException() {
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message. The
+ * cause is not initialized, and may subsequently be initialized by
+ * a call to {@link #initCause}.
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public ParseException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public ParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public ParseException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/classification/Classification.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/classification/Classification.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/classification/Classification.java
new file mode 100644
index 0000000..3bee617
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/classification/Classification.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.classification;
+
+import at.newmedialab.lmf.client.model.rdf.URI;
+
+
+/**
+ * A classification result of the classifier; for each category, provides a probability value indicating how much
+ * the text fits to a category.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class Classification implements Comparable<Classification> {
+
+
+ private URI category;
+ private double probability;
+
+ public Classification(URI category, double probability) {
+ this.category = category;
+ this.probability = probability;
+ }
+
+ /**
+ * The category for which the classifier computed a probability
+ *
+ * @return
+ */
+ public URI getCategory() {
+ return category;
+ }
+
+ /**
+ * The probability the text fits to this category.
+ *
+ * @return
+ */
+ public double getProbability() {
+ return probability;
+ }
+
+ /**
+ * Compares this object with the specified object for order. Returns a
+ * negative integer, zero, or a positive integer as this object is less
+ * than, equal to, or greater than the specified object.
+ * <p/>
+ * Classifiers with higher probability take precedence (are smaller) than classifiers with lower probability.
+ *
+ * @param o the object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ * @throws ClassCastException if the specified object's type prevents it
+ * from being compared to this object.
+ */
+ @Override
+ public int compareTo(Classification o) {
+ if(getProbability() > o.getProbability()) {
+ return -1;
+ } else if(getProbability() < o.getProbability()) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/config/Configuration.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/config/Configuration.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/config/Configuration.java
new file mode 100644
index 0000000..11593be
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/config/Configuration.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.config;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class Configuration {
+
+ private String key;
+
+ private Object value;
+
+
+ public Configuration(String key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+
+ public String getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public String getString() {
+ if(value instanceof Collection) {
+ if(((Collection) value).isEmpty()) {
+ return null;
+ } else {
+ return ((Collection) value).iterator().next().toString();
+ }
+ } else {
+ return value.toString();
+ }
+ }
+
+ public List<String> getList() {
+ List<String> result = new ArrayList<String>();
+ if(value instanceof Collection) {
+ for(Object o : (Collection) value) {
+ result.add(o.toString());
+ }
+ } else {
+ result.add(value.toString());
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/ByteContent.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/ByteContent.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/ByteContent.java
new file mode 100644
index 0000000..6814b58
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/ByteContent.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.content;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ByteContent extends Content {
+
+ private byte[] bytes;
+
+ public ByteContent(byte[] bytes, String mimeType, long size) {
+ super(mimeType, size);
+ this.bytes = bytes;
+ }
+
+ /**
+ * Return the content of this object as stream. Note that the stream is only guaranteed to be consumable once.
+ *
+ * @return
+ */
+ @Override
+ public InputStream getStream() {
+ return new ByteArrayInputStream(bytes);
+ }
+
+ /**
+ * Return the content of this object as byte array. Note that when calling this method it is not safe to
+ * call the getStream method afterwards.
+ *
+ * @return
+ */
+ @Override
+ public byte[] getBytes() {
+ return bytes;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/Content.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/Content.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/Content.java
new file mode 100644
index 0000000..3c6029d
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/Content.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.content;
+
+import java.io.InputStream;
+
+/**
+ * Representation of media content returned by the Linked Media Framework. Provides an InputStream for
+ * reading the media data. Optionally, supports reading all content into a byte array.
+ *
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public abstract class Content {
+
+ private String mimeType;
+
+ private long size;
+
+
+ public Content(String mimeType, long size) {
+ this.mimeType = mimeType;
+ this.size = size;
+ }
+
+ /**
+ * Return the content of this object as stream. Note that the stream is only guaranteed to be consumable once.
+ * @return
+ */
+ public abstract InputStream getStream();
+
+
+ /**
+ * Return the content of this object as byte array. Note that when calling this method it is not safe to
+ * call the getStream method afterwards.
+ * @return
+ */
+ public abstract byte[] getBytes();
+
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ public long getSize() {
+ return size;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StreamContent.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StreamContent.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StreamContent.java
new file mode 100644
index 0000000..a0a8747
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StreamContent.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.content;
+
+import com.google.common.io.ByteStreams;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class StreamContent extends Content {
+
+ private InputStream data;
+
+ public StreamContent(InputStream data, String mimeType, long size) {
+ super(mimeType, size);
+ this.data = data;
+ }
+
+ /**
+ * Return the content of this object as stream. Note that the stream is only guaranteed to be consumable once.
+ *
+ * @return
+ */
+ @Override
+ public InputStream getStream() {
+ return data;
+ }
+
+ /**
+ * Return the content of this object as byte array. Note that when calling this method it is not safe to
+ * call the getStream method afterwards.
+ *
+ * @return
+ */
+ @Override
+ public byte[] getBytes() {
+ try {
+ return ByteStreams.toByteArray(data);
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StringContent.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StringContent.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StringContent.java
new file mode 100644
index 0000000..9b5bfe2
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/content/StringContent.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.content;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class StringContent extends Content {
+
+ private String data;
+
+ public StringContent(String data, String mimeType) {
+ super(mimeType, data.getBytes().length);
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ /**
+ * Return the content of this object as stream. Note that the stream is only guaranteed to be consumable once.
+ *
+ * @return
+ */
+ @Override
+ public InputStream getStream() {
+ return new ByteArrayInputStream(getBytes());
+ }
+
+ /**
+ * Return the content of this object as byte array. Note that when calling this method it is not safe to
+ * call the getStream method afterwards.
+ *
+ * @return
+ */
+ @Override
+ public byte[] getBytes() {
+ try {
+ return data.getBytes("utf-8");
+ } catch (UnsupportedEncodingException e) {
+ return data.getBytes();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/meta/Metadata.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/meta/Metadata.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/meta/Metadata.java
new file mode 100644
index 0000000..1f711a9
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/meta/Metadata.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.meta;
+
+import at.newmedialab.lmf.client.model.rdf.Literal;
+import at.newmedialab.lmf.client.model.rdf.RDFNode;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class Metadata extends HashMap<String,Set<RDFNode>> {
+
+ private String subject;
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the default initial capacity
+ * (16) and the default load factor (0.75).
+ */
+ public Metadata(String subject) {
+ this.subject = subject;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public RDFNode getFirst(String propertyUri) {
+ Preconditions.checkNotNull(get(propertyUri));
+ Preconditions.checkState(get(propertyUri).iterator().hasNext());
+
+ return get(propertyUri).iterator().next();
+ }
+
+
+ /**
+ * Convert a more simple property map into a metadata representation. Note that all keys of the property map still
+ * are required to be valid RDF URI resources. All properties will have string literal values in the resulting metadata.
+ *
+ * @param resource
+ * @param map
+ * @return
+ */
+ public static Metadata fromPropertiesMap(String resource, Map<String,String> map) {
+ Metadata m = new Metadata(resource);
+ for(Map.Entry<String,String> entry : map.entrySet()) {
+ m.put(entry.getKey(), ImmutableSet.<RDFNode>of(new Literal(entry.getValue())));
+ }
+ return m;
+ }
+
+ /**
+ * Convert a metadata representation into a simpler property map, potentially loosing information. Only the
+ * first literal value of a property is copied to the resulting map.
+ *
+ * @param metadata
+ * @return
+ */
+ public static Map<String,String> toPropertiesMap(Metadata metadata) {
+ Map<String,String> result = new HashMap<String, String>();
+ for(Map.Entry<String,Set<RDFNode>> entry : metadata.entrySet()) {
+ for(RDFNode n : entry.getValue()) {
+ if(n instanceof Literal) {
+ result.put(entry.getKey(),((Literal) n).getContent());
+ break;
+ }
+ }
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/BNode.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/BNode.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/BNode.java
new file mode 100644
index 0000000..58f8e66
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/BNode.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.rdf;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class BNode extends RDFNode {
+
+ private String anonId;
+
+ public BNode(String anonId) {
+ this.anonId = anonId;
+ }
+
+ public String getAnonId() {
+ return anonId;
+ }
+
+ public void setAnonId(String anonId) {
+ this.anonId = anonId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BNode bNode = (BNode) o;
+
+ if (anonId != null ? !anonId.equals(bNode.anonId) : bNode.anonId != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return anonId != null ? anonId.hashCode() : 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/Literal.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/Literal.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/Literal.java
new file mode 100644
index 0000000..4374233
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/Literal.java
@@ -0,0 +1,120 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.rdf;
+
+/**
+ * A lightweight RDF Literal implementation providing the base functionalities.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class Literal extends RDFNode {
+
+ private String content;
+
+ private String language;
+
+ private URI type;
+
+
+ public Literal(String content) {
+ this.content = content;
+ }
+
+ public Literal(String content, String language) {
+ this.content = content;
+ this.language = language;
+ }
+
+ public Literal(String content, URI type) {
+ this.content = content;
+ this.type = type;
+ }
+
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public URI getType() {
+ return type;
+ }
+
+ public void setType(URI type) {
+ this.type = type;
+ }
+
+
+ public int getInt() {
+ return Integer.parseInt(content);
+ }
+
+ public long getLong() {
+ return Long.parseLong(content);
+ }
+
+ public double getDouble() {
+ return Double.parseDouble(content);
+ }
+
+ public float getFloat() {
+ return Float.parseFloat(content);
+ }
+
+ public boolean getBoolean() {
+ return Boolean.getBoolean(content);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Literal literal = (Literal) o;
+
+ if (!content.equals(literal.content)) return false;
+ if (language != null ? !language.equals(literal.language) : literal.language != null) return false;
+ if (type != null ? !type.equals(literal.type) : literal.type != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = content.hashCode();
+ result = 31 * result + (language != null ? language.hashCode() : 0);
+ result = 31 * result + (type != null ? type.hashCode() : 0);
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return content;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/RDFNode.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/RDFNode.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/RDFNode.java
new file mode 100644
index 0000000..ec4da16
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/RDFNode.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.rdf;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class RDFNode {
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/URI.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/URI.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/URI.java
new file mode 100644
index 0000000..07c4f94
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/rdf/URI.java
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.rdf;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class URI extends RDFNode {
+
+ private String uri;
+
+ public URI(String uri) {
+ this.uri = uri;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ URI uri1 = (URI) o;
+
+ if (!uri.equals(uri1.uri)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return uri.hashCode();
+ }
+
+ /**
+ * Returns a string representation of the object. In general, the
+ * <code>toString</code> method returns a string that
+ * "textually represents" this object. The result should
+ * be a concise but informative representation that is easy for a
+ * person to read.
+ * It is recommended that all subclasses override this method.
+ * <p/>
+ * The <code>toString</code> method for class <code>Object</code>
+ * returns a string consisting of the name of the class of which the
+ * object is an instance, the at-sign character `<code>@</code>', and
+ * the unsigned hexadecimal representation of the hash code of the
+ * object. In other words, this method returns a string equal to the
+ * value of:
+ * <blockquote>
+ * <pre>
+ * getClass().getName() + '@' + Integer.toHexString(hashCode())
+ * </pre></blockquote>
+ *
+ * @return a string representation of the object.
+ */
+ @Override
+ public String toString() {
+ return uri;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/sparql/SPARQLResult.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/sparql/SPARQLResult.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/sparql/SPARQLResult.java
new file mode 100644
index 0000000..2421b79
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/model/sparql/SPARQLResult.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.model.sparql;
+
+import at.newmedialab.lmf.client.model.rdf.RDFNode;
+
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provides a list of result bindings and information about the available fields.
+ *
+ * @author Sebastian Schaffert
+ */
+public class SPARQLResult extends LinkedList<Map<String,RDFNode>> {
+
+ private static final long serialVersionUID = -527039638847863378L;
+
+ private Set<String> fieldNames;
+
+ /**
+ * Constructs an empty list.
+ */
+ public SPARQLResult(Set<String> fieldNames) {
+ this.fieldNames = fieldNames;
+ }
+
+
+ public Set<String> getFieldNames() {
+ return fieldNames;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/HTTPUtil.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/HTTPUtil.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/HTTPUtil.java
new file mode 100644
index 0000000..fc3b7b7
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/HTTPUtil.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.util;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.LMFClient;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.ProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultRedirectStrategy;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+
+import java.io.IOException;
+
+/**
+ * HTTP Utilities
+ *
+ * @author Sebastian Schaffert
+ * @author Sergio Fernández
+ */
+public class HTTPUtil {
+
+ private static final String CONTEXT = "context";
+
+ public static HttpClient createClient(ClientConfiguration config) {
+
+ HttpParams httpParams = new BasicHttpParams();
+ httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "LMF Client Library "+ LMFClient.VERSION);
+
+ httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSoTimeout());
+ httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout());
+
+ httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,true);
+ httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS,3);
+
+ if (StringUtils.isNotBlank(config.getLmfContext())) {
+ httpParams.setParameter(CONTEXT, config.getLmfContext());
+ }
+
+ DefaultHttpClient client;
+ if (config.getConectionManager() != null) {
+ client = new DefaultHttpClient(config.getConectionManager(), httpParams);
+ } else {
+ client = new DefaultHttpClient(httpParams);
+ }
+ client.setRedirectStrategy(new LMFRedirectStrategy());
+ client.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler());
+ return client;
+ }
+
+ public static HttpPost createPost(String path, ClientConfiguration config) {
+ String serviceUrl = config.getLmfUri() + path ;
+
+ //FIXME: switch to a more elegant way, such as Jersey's UriBuilder
+ if (StringUtils.isNotBlank(config.getLmfContext())) {
+ serviceUrl += "?" + CONTEXT + "=" + config.getLmfContext();
+ }
+
+ return new HttpPost(serviceUrl);
+ }
+
+
+ private static class LMFRedirectStrategy extends DefaultRedirectStrategy {
+ @Override
+ public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
+ if (response == null) {
+ throw new IllegalArgumentException("HTTP response may not be null");
+ }
+
+ int statusCode = response.getStatusLine().getStatusCode();
+ String method = request.getRequestLine().getMethod();
+ Header locationHeader = response.getFirstHeader("location");
+ switch (statusCode) {
+ case HttpStatus.SC_MOVED_TEMPORARILY:
+ return (method.equalsIgnoreCase(HttpGet.METHOD_NAME)
+ || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) && locationHeader != null;
+ case HttpStatus.SC_MOVED_PERMANENTLY:
+ case HttpStatus.SC_TEMPORARY_REDIRECT:
+ return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
+ || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
+ case HttpStatus.SC_SEE_OTHER:
+ return true;
+ case HttpStatus.SC_MULTIPLE_CHOICES:
+ return true;
+ default:
+ return false;
+ } //end of switch
+ }
+ }
+
+ private static class LMFHttpRequestRetryHandler implements HttpRequestRetryHandler {
+ /**
+ * Determines if a method should be retried after an IOException
+ * occurs during execution.
+ *
+ * @param exception the exception that occurred
+ * @param executionCount the number of times this method has been
+ * unsuccessfully executed
+ * @param context the context for the request execution
+ * @return <code>true</code> if the method should be retried, <code>false</code>
+ * otherwise
+ */
+ @Override
+ public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
+ return false;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/KiWiCollections.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/KiWiCollections.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/KiWiCollections.java
new file mode 100644
index 0000000..530bb66
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/KiWiCollections.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.util;
+
+import java.text.Format;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class contains static helper methods for supporting java collections
+ * in Java 5.
+ *
+ * @author Sebastian Schaffert
+ */
+public class KiWiCollections {
+
+ /**
+ * Convert any iterable into a list
+ * @param <T>
+ * @param iterable
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> toList(Iterable<T> iterable) {
+ return toCollection(LinkedList.class,iterable);
+ }
+
+ /**
+ * Convert any iterable into a set
+ * @param <T>
+ * @param iterable
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> Set<T> toSet(Iterable<T> iterable) {
+ return toCollection(HashSet.class,iterable);
+ }
+
+ private static <C extends Collection<T>,T> C toCollection(Class<C> cls, Iterable<T> iterable) {
+ try {
+ C result = cls.newInstance();
+
+ for(T item : iterable) {
+ result.add(item);
+ }
+
+ return result;
+ } catch(InstantiationException ex) {
+ return null;
+ } catch(IllegalAccessException ex) {
+ return null;
+ }
+ }
+
+ public static <T> T first(Iterable<T> iterable) {
+ return iterable.iterator().next();
+ }
+
+
+ public static <T> String fold(Collection<T> elements, String separator) {
+ StringBuilder builder = new StringBuilder();
+ ArrayList<T> list = new ArrayList<T>(elements);
+ for(int i=0; i<list.size(); i++) {
+ builder.append(list.get(i).toString());
+ if(i < list.size()-1) {
+ builder.append(separator);
+ }
+ }
+ return builder.toString();
+ }
+
+
+ public static <T> String fold(Collection<T> elements, Format format, String separator) {
+ StringBuilder builder = new StringBuilder();
+ ArrayList<T> list = new ArrayList<T>(elements);
+ for(int i=0; i<list.size(); i++) {
+ builder.append(format.format(list.get(i)));
+ if(i < list.size()-1) {
+ builder.append(separator);
+ }
+ }
+ return builder.toString();
+ }
+
+ public static <T> String fold(Collection<T> elements, StringSerializer<T> format, String separator) {
+ StringBuilder builder = new StringBuilder();
+ ArrayList<T> list = new ArrayList<T>(elements);
+ for(int i=0; i<list.size(); i++) {
+ builder.append(format.serialize(list.get(i)));
+ if(i < list.size()-1) {
+ builder.append(separator);
+ }
+ }
+ return builder.toString();
+ }
+
+
+ /**
+ * Concatenate the collection of lists passed as argument into a new array list.
+ * @param lists
+ * @param <T>
+ * @return
+ */
+ public static <T> List<T> concat(Collection<? extends Collection<T>> lists) {
+ int size = 0;
+ for(Collection<T> list : lists) {
+ size += list.size();
+ }
+ List<T> result = new ArrayList<T>(size);
+ for(Collection<T> list : lists) {
+ result.addAll(list);
+ }
+ return result;
+ }
+
+
+ public interface StringSerializer<T> {
+ public String serialize(T t);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/RDFJSONParser.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/RDFJSONParser.java b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/RDFJSONParser.java
new file mode 100644
index 0000000..9000647
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/main/java/at/newmedialab/lmf/client/util/RDFJSONParser.java
@@ -0,0 +1,148 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.newmedialab.lmf.client.util;
+
+import at.newmedialab.lmf.client.exception.ParseException;
+import at.newmedialab.lmf.client.model.meta.Metadata;
+import at.newmedialab.lmf.client.model.rdf.BNode;
+import at.newmedialab.lmf.client.model.rdf.Literal;
+import at.newmedialab.lmf.client.model.rdf.RDFNode;
+import at.newmedialab.lmf.client.model.rdf.URI;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Parse RDF/JSON into a map-based representation.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class RDFJSONParser {
+
+ private static final String HTTP = "http://";
+ private static final String VALUE = "value";
+ private static final String TYPE = "type";
+ private static final String TYPE_BNODE = "bnode";
+ private static final String TYPE_URI = "uri";
+ private static final String TYPE_LITERAL = "literal";
+ private static final String LANG = "lang";
+ private static final String DATATYPE = "datatype";
+
+ public static Map<String,Metadata> parseRDFJSON(InputStream data) throws ParseException {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ Map<String,Map<String,Set<Map<String,String>>>> subjects = mapper.readValue(data, new TypeReference<Map<String,Map<String,Set<Map<String,String>>>>>(){});
+
+ // convert "raw" map into a map to Metadata objects
+ Map<String,Metadata> result = new HashMap<String, Metadata>();
+ for(Map.Entry<String,Map<String,Set<Map<String,String>>>> subject : subjects.entrySet()) {
+ Metadata m = new Metadata(subject.getKey());
+ result.put(subject.getKey(),m);
+
+ for(Map.Entry<String,Set<Map<String,String>>> property : subject.getValue().entrySet()) {
+ Set<RDFNode> propValue = new HashSet<RDFNode>();
+ for(Map<String,String> value : property.getValue()) {
+ propValue.add(parseRDFJSONNode(value));
+ }
+ m.put(property.getKey(),propValue);
+ }
+ }
+ return result;
+
+ } catch (IOException e) {
+ throw new ParseException("could not parse JSON data",e);
+ }
+
+ }
+
+ /**
+ * Parse the representation of a node in RDF/JSON into an RDFNode object
+ * @param nodeDef
+ * @return
+ */
+ public static RDFNode parseRDFJSONNode(Map<String, String> nodeDef) {
+ RDFNode object;
+
+ if( nodeDef.get(TYPE).equals(TYPE_URI) ) {
+ object = new URI(nodeDef.get(VALUE));
+ } else if( nodeDef.get(TYPE).equals(TYPE_BNODE) ) {
+ object = new BNode(nodeDef.get(VALUE));
+ } else {
+ if( nodeDef.get(LANG) != null ) {
+ object = new Literal(nodeDef.get(VALUE),nodeDef.get(LANG));
+ } else if( nodeDef.get(DATATYPE) != null) {
+ object = new Literal(nodeDef.get(VALUE),new URI(nodeDef.get(DATATYPE)));
+ } else {
+ object = new Literal(nodeDef.get(VALUE));
+ }
+ }
+ return object;
+ }
+
+
+ public static void serializeRDFJSON(Map<String,Metadata> data, OutputStream out) throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+
+
+ Map<String,Map<String,Set<Map<String,String>>>> subjects = new HashMap<String, Map<String, Set<Map<String, String>>>>();
+
+
+ for(Map.Entry<String,Metadata> subject : data.entrySet()) {
+ //add or get predicate map
+ Map<String,Set<Map<String,String>>> predicates = new HashMap<String,Set<Map<String,String>>>();
+ subjects.put(subject.getKey(),predicates);
+
+
+ for(Map.Entry<String,Set<RDFNode>> predicate : subject.getValue().entrySet()) {
+ //add or get object set
+ Set<Map<String,String>> objects = new HashSet<Map<String,String>>();
+ predicates.put(predicate.getKey(),objects);
+
+ //add objects
+ for(RDFNode objectNode : predicate.getValue()) {
+ Map<String,String> object = new HashMap<String,String>();
+ if( objectNode instanceof Literal) {
+ object.put(TYPE,TYPE_LITERAL);
+ object.put(VALUE,((Literal)objectNode).getContent());
+ if(((Literal) objectNode).getLanguage() != null )
+ object.put(LANG,((Literal) objectNode).getLanguage());
+ if(((Literal) objectNode).getType() != null)
+ object.put(DATATYPE,((Literal) objectNode).getType().getUri());
+ } else {
+ if( objectNode instanceof URI ) {
+ object.put(TYPE,TYPE_URI);
+ object.put(VALUE,((URI)objectNode).getUri());
+ } else {
+ object.put(TYPE,TYPE_BNODE);
+ object.put(VALUE,((BNode)objectNode).getAnonId());
+ }
+ }
+ objects.add(object);
+ }
+ }
+
+ }
+ mapper.writeValue(out,subjects);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/classification/ClassificationIT.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/classification/ClassificationIT.java b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/classification/ClassificationIT.java
new file mode 100644
index 0000000..301b5d9
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/classification/ClassificationIT.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012 Salzburg Research
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.newmedialab.lmf.client.test.classification;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.clients.ClassificationClient;
+import at.newmedialab.lmf.client.clients.ResourceClient;
+import at.newmedialab.lmf.client.model.classification.Classification;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ClassificationIT {
+
+
+ private static ClientConfiguration config;
+
+ @BeforeClass
+ public static void init() {
+ config = new ClientConfiguration("http://localhost:8080/LMF");
+
+ }
+
+
+ @Ignore
+ @Test
+ public void testCreateListDelete() throws Exception {
+ ClassificationClient client = new ClassificationClient(config);
+
+ String id = "testclassify";
+ client.createClassifier(id.toString());
+
+ Assert.assertThat(client.listClassifiers(), Matchers.hasItem(id.toString()));
+
+ client.removeClassifier(id.toString(),true);
+
+ Assert.assertTrue(client.listClassifiers().size() == 0);
+ }
+
+ @Ignore
+ @Test
+ public void testCreateAndTrainClassifier() throws Exception {
+ ClassificationClient client = new ClassificationClient(config);
+ ResourceClient resourceClient = new ResourceClient(config);
+
+ resourceClient.createResource("http://www.example.com/Concept1");
+ resourceClient.createResource("http://www.example.com/Concept2");
+
+ String id = "testclassify";
+ client.createClassifier(id.toString());
+
+ client.trainClassifier(id,"http://www.example.com/Concept1","Major acquisitions that have a lower gross margin than the existing network also " +
+ " had a negative impact on the overall gross margin, but it should improve following " +
+ " the implementation of its integration strategies .");
+ client.trainClassifier(id,"http://www.example.com/Concept2","The upward movement of gross margin resulted from amounts pursuant to adjustments " +
+ " to obligations towards dealers .");
+
+ client.retrainClassifier(id);
+
+ Thread.sleep(10000);
+ client.removeClassifier(id,true);
+ }
+
+
+ @Ignore
+ @Test
+ public void testCreateAndTrainAndClassifyClassifier() throws Exception {
+ ClassificationClient client = new ClassificationClient(config);
+ ResourceClient resourceClient = new ResourceClient(config);
+
+ resourceClient.createResource("http://www.example.com/Concept1");
+ resourceClient.createResource("http://www.example.com/Concept2");
+
+ String id = "testclassify";
+ client.createClassifier(id.toString());
+
+ client.trainClassifier(id,"http://www.example.com/Concept1","Major acquisitions that have a lower gross margin than the existing network also " +
+ " had a negative impact on the overall gross margin, but it should improve following " +
+ " the implementation of its integration strategies .");
+ client.trainClassifier(id,"http://www.example.com/Concept2","The upward movement of gross margin resulted from amounts pursuant to adjustments " +
+ " to obligations towards dealers .");
+
+ client.retrainClassifier(id);
+
+
+ List<Classification> result = client.getAllClassifications(id,"Major acquisitions that have a lower gross margin than the existing network");
+ Assert.assertTrue(result.size()==2);
+ Assert.assertTrue(result.get(0).getCategory().getUri().equals("http://www.example.com/Concept1"));
+
+
+ client.removeClassifier(id,true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/config/ConfigurationIT.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/config/ConfigurationIT.java b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/config/ConfigurationIT.java
new file mode 100644
index 0000000..fd66dd4
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/config/ConfigurationIT.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2012 Salzburg Research
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.newmedialab.lmf.client.test.config;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.clients.ConfigurationClient;
+import at.newmedialab.lmf.client.exception.LMFClientException;
+import at.newmedialab.lmf.client.model.config.Configuration;
+import com.google.common.collect.Lists;
+import kiwi.core.test.base.JettyLMF;
+import kiwi.core.webservices.config.ConfigurationWebService;
+import org.hamcrest.Matchers;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ConfigurationIT {
+
+
+ private static JettyLMF lmf;
+
+ private static ClientConfiguration config;
+
+ @BeforeClass
+ public static void init() {
+ lmf = new JettyLMF("/LMF",8080, ConfigurationWebService.class);
+
+ config = new ClientConfiguration("http://localhost:8080/LMF");
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ lmf.shutdown();
+ }
+
+
+
+ @Test
+ public void testListConfigurationKeys() throws LMFClientException, IOException {
+ ConfigurationClient client = new ConfigurationClient(config);
+
+ Set<String> keys = client.listConfigurationKeys();
+ Assert.assertNotNull(keys);
+ Assert.assertThat(keys, Matchers.hasItem("solr.cores.enabled"));
+ }
+
+ @Test
+ public void testListConfigurations() throws LMFClientException, IOException {
+ ConfigurationClient client = new ConfigurationClient(config);
+
+ Set<Configuration> cfgs1 = client.listConfigurations(null);
+ Assert.assertNotNull(cfgs1);
+ Assert.assertTrue(cfgs1.size() > 0);
+
+
+ Set<Configuration> cfgs2 = client.listConfigurations("solr");
+ Assert.assertNotNull(cfgs2);
+ Assert.assertTrue(cfgs2.size() > 0);
+
+ Set<Configuration> cfgs3 = client.listConfigurations("brzlbrnft");
+ Assert.assertNotNull(cfgs3);
+ Assert.assertTrue(cfgs3.size() == 0);
+ }
+
+ @Test
+ public void testGetConfiguration() throws LMFClientException, IOException {
+ ConfigurationClient client = new ConfigurationClient(config);
+
+ Configuration c_version = client.getConfiguration("kiwi.version");
+ Assert.assertNotNull(c_version);
+
+ Configuration c_path = client.getConfiguration("kiwi.path");
+ Assert.assertNotNull(c_path);
+ Assert.assertEquals("/LMF",c_path.getString());
+
+ Configuration c_allow = client.getConfiguration("kiwi.allow_methods");
+ Assert.assertNotNull(c_allow);
+ Assert.assertThat(c_allow.getList(),Matchers.hasItem("POST"));
+ }
+
+
+ @Test
+ public void testSetConfiguration() throws LMFClientException, IOException {
+ ConfigurationClient client = new ConfigurationClient(config);
+
+ // set a single-value string configuration
+ client.setConfiguration("lmfclient.test.single","abc");
+ Configuration c_single = client.getConfiguration("lmfclient.test.single");
+ Assert.assertNotNull(c_single);
+ Assert.assertEquals("abc",c_single.getString());
+ client.deleteConfiguration("lmfclient.test.single");
+ c_single = client.getConfiguration("lmfclient.test.single");
+ Assert.assertNull(c_single);
+
+ // set a single-value boolean configuration
+ client.setConfiguration("lmfclient.test.bool",true);
+ Configuration c_bool = client.getConfiguration("lmfclient.test.bool");
+ Assert.assertNotNull(c_bool);
+ Assert.assertEquals("true",c_bool.getString());
+ client.deleteConfiguration("lmfclient.test.bool");
+ c_bool = client.getConfiguration("lmfclient.test.bool");
+ Assert.assertNull(c_bool);
+
+
+ // set a list value configuration
+ client.setConfiguration("lmfclient.test.list", Lists.newArrayList("abc","efg","hij"));
+ Configuration c_list = client.getConfiguration("lmfclient.test.list");
+ Assert.assertNotNull(c_list);
+ Assert.assertThat(c_list.getList(), Matchers.hasItem("efg"));
+ client.deleteConfiguration("lmfclient.test.list");
+ c_list = client.getConfiguration("lmfclient.test.list");
+ Assert.assertNull(c_list);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/io/ImportIT.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/io/ImportIT.java b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/io/ImportIT.java
new file mode 100644
index 0000000..f0884d6
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/io/ImportIT.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.newmedialab.lmf.client.test.io;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.clients.ImportClient;
+import at.newmedialab.lmf.client.clients.ResourceClient;
+import at.newmedialab.lmf.client.exception.LMFClientException;
+import at.newmedialab.lmf.client.model.meta.Metadata;
+import kiwi.core.test.base.JettyLMF;
+import kiwi.core.webservices.io.ImportWebService;
+import kiwi.core.webservices.resource.MetaWebService;
+import kiwi.core.webservices.resource.ResourceWebService;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ImportIT {
+
+ private static JettyLMF lmf;
+
+ private static ClientConfiguration config;
+
+ @BeforeClass
+ public static void init() {
+ lmf = new JettyLMF("/LMF", 8080, ImportWebService.class, ResourceWebService.class, MetaWebService.class);
+
+ config = new ClientConfiguration("http://localhost:8080/LMF");
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ lmf.shutdown();
+ }
+
+
+
+ @Test
+ public void testUpload() throws IOException, LMFClientException {
+ ImportClient client = new ImportClient(config);
+
+ String data = "<http://example.com/resource/r1> <http://example.com/resource/p1> \"Test Data\".";
+ client.uploadDataset(data,"text/rdf+n3");
+
+ ResourceClient resourceClient = new ResourceClient(config);
+ Metadata m = resourceClient.getResourceMetadata("http://example.com/resource/r1");
+ Assert.assertNotNull(m);
+ Assert.assertEquals(1,m.size());
+ Assert.assertEquals("Test Data", m.getFirst("http://example.com/resource/p1").toString());
+
+ resourceClient.deleteResource("http://example.com/resource/r1");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/ldpath/LDPathIT.java
----------------------------------------------------------------------
diff --git a/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/ldpath/LDPathIT.java b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/ldpath/LDPathIT.java
new file mode 100644
index 0000000..0f74081
--- /dev/null
+++ b/lmf-client/lmf-client-java/src/test/java/at/newmedialab/lmf/client/test/ldpath/LDPathIT.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.newmedialab.lmf.client.test.ldpath;
+
+import at.newmedialab.lmf.client.ClientConfiguration;
+import at.newmedialab.lmf.client.clients.LDPathClient;
+import at.newmedialab.lmf.client.model.rdf.RDFNode;
+import at.newmedialab.lmf.ldpath.webservices.LDPathWebService;
+import kiwi.core.api.importer.ImportService;
+import kiwi.core.exception.io.LMFImportException;
+import kiwi.core.test.base.JettyLMF;
+import org.hamcrest.CoreMatchers;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.Matchers.*;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDPathIT {
+
+
+ private static JettyLMF lmf;
+
+ private static ClientConfiguration config;
+
+ // the tests require the demo-data.foaf to be loaded; we do so by first calling the import service before we start with tests
+ private static ImportService importService;
+
+ @BeforeClass
+ public static void init() throws LMFImportException {
+ lmf = new JettyLMF("/LMF",8080, LDPathWebService.class);
+
+ config = new ClientConfiguration("http://localhost:8080/LMF");
+
+ importService = lmf.getService(ImportService.class);
+
+ // load initial data
+ InputStream data = LDPathIT.class.getResourceAsStream("/demo-data.foaf");
+
+ importService.importData(data,"application/rdf+xml",null,null);
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ lmf.shutdown();
+ }
+
+
+ @Test
+ public void testPath() throws Exception {
+ LDPathClient client = new LDPathClient(config);
+
+ List<RDFNode> result = client.evaluatePath("http://localhost:8080/LMF/resource/anna_schmidt", "foaf:knows / foaf:name");
+ Assert.assertThat(result, CoreMatchers.<RDFNode> hasItem(hasProperty("content", equalTo("Sepp Huber"))));
+ }
+
+
+ @Test
+ public void testProgram() throws Exception {
+ LDPathClient client = new LDPathClient(config);
+
+ Map<String, List<RDFNode>> result = client.evaluateProgram("http://localhost:8080/LMF/resource/hans_meier", "friend = foaf:knows / foaf:name :: xsd:string; name = foaf:name :: xsd:string; interest = foaf:interest / (rdfs:label[@en] | rdfs:label[@none] | <http://rdf.freebase.com/ns/type.object.name>[@en]) :: xsd:string;");
+ Assert.assertThat(result,hasKey("interest"));
+ Assert.assertThat(result.get("interest"), CoreMatchers.<RDFNode> hasItem(hasProperty("content", equalTo("GNU/Linux"))));
+
+ }
+}