Skip to content
Snippets Groups Projects
Commit d270d313 authored by Qawasmeh-omar's avatar Qawasmeh-omar
Browse files

keyword search is integrated

parent f314065f
No related branches found
No related tags found
No related merge requests found
Showing
with 496 additions and 3 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>saref-server</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
XDOCLETBUILDERACTIVE=true
XDOCLETHOME=
XDOCLETUSEGLOBAL=true
XDOCLETVERSION=1.2.1
eclipse.preferences.version=1
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="ROOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="ROOT"/>
<property name="java-output-path" value="/saref-server/target/classes"/>
</wb-module>
</project-modules>
<root>
<facet id="jst.jaxrs">
<node name="libprov">
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
</node>
</facet>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Window
\ No newline at end of file
disabled=06target
eclipse.preferences.version=1
...@@ -78,6 +78,16 @@ ...@@ -78,6 +78,16 @@
<version>9.4.14.v20181114</version> <version>9.4.14.v20181114</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-text</artifactId>
<version>${jena.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>${jena.version}</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -32,7 +32,7 @@ import javax.ws.rs.core.MediaType; ...@@ -32,7 +32,7 @@ import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.server.mvc.Template; import org.glassfish.jersey.server.mvc.Template;
@Path("/view") @Path("/{p: (index\\.html)?}")
public class ListExercises { public class ListExercises {
@GET @GET
......
/**
*
*/
package org.etsi.saref.server.resources;
import java.io.IOException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.server.mvc.Template;
import java.awt.Desktop;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
/**
* @author Omar Qawasmeh
*
*
*/
@Path("/search")
public class Search {
@GET
@Produces(MediaType.TEXT_HTML)
@Template(name = "/index")
public String doSearch(@QueryParam("q") String keyword) throws IOException {
// String results;
MustacheFactory mf = new DefaultMustacheFactory();
Mustache m = mf.compile("templates/index.mustache");
SearchKeyWord queryResults = new SearchKeyWord();
// "has meter reading type"
queryResults.setSearchResultsLabels(keyword);
// results=queryResults.getSearchResultsLabels();
System.out.println(queryResults.getSearchResultsLabels());
StringWriter writer = new StringWriter();
System.out.println("Before:" + writer.toString());
m.execute(writer, queryResults).flush();
writer.close();
System.out.println("After:" + writer);
String html = writer.toString();
FileWriter fw = new FileWriter("src/main/resources/saref-portal-generator/public/keywordSearchPage.html");
StringWriter sw = new StringWriter();
sw.write(html);
fw.write(sw.toString());
fw.close();
File htmlFile = new File("src/main/resources/saref-portal-generator/public/keywordSearchPage.html");
Desktop.getDesktop().browse(htmlFile.toURI());
return writer.toString();
}
}
/**
*
*/
package org.etsi.saref.server.resources;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.query.text.EntityDefinition;
import org.apache.jena.query.text.TextDatasetFactory;
import org.apache.jena.query.text.TextIndexConfig;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.sparql.util.QueryExecUtils;
import org.apache.jena.vocabulary.RDFS;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
/**
* @author Omar Qawasmeh
*/
public class SearchKeyWord {
private static final String DS = "http://localhost:3030/test-sarefTtl/data";
private String searchResultsLabels;
private String title;
private Dataset ds;
public SearchKeyWord() {
ds = createCode();
loadData(ds, DS);
}
/**
* @return the searchResultsLabels
*/
public String getSearchResultsLabels() {
return searchResultsLabels;
}
public void setSearchResultsLabels(String searchResultsLabels) {
this.searchResultsLabels = queryDataLabels(ds, searchResultsLabels);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = queryDataLabels(ds, "has meter reading type");
}
// public static void main(String args[]) {
// queryDataComment(ds, "some measurements that are characterized by a
// certain value ");
// }
public static Dataset createCode() {
Dataset ds1 = DatasetFactory.create();
// EntityDefinition entDef = new EntityDefinition("uri", "text",
// RDFS.label) ;
EntityDefinition entDef = new EntityDefinition("uri", "text");
entDef.setPrimaryPredicate(RDFS.label.asNode());
entDef.setPrimaryPredicate(RDFS.comment.asNode());
Directory dir = new RAMDirectory();
Dataset ds = TextDatasetFactory.createLucene(ds1, dir, new TextIndexConfig(entDef));
return ds;
}
public static void loadData(Dataset dataset, String TtlFileLocation) {
// dataset.begin(ReadWrite.WRITE);
try {
Model m = dataset.getDefaultModel();
RDFDataMgr.read(m, TtlFileLocation);
dataset.commit();
} finally {
dataset.end();
}
}
public static String queryDataLabels(Dataset dataset, String kw) {
String queryResults;
String queryString = "PREFIX : <http://example/>" + "PREFIX text: <http://jena.apache.org/text#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "SELECT * " + " { "
+ "?s text:query (rdfs:label '" + kw + "') ;" + " rdfs:label ?label" + " } limit 10";
dataset.begin(ReadWrite.READ);
try {
Query q = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet qresults = qexec.execSelect();
queryResults = ResultSetFormatter.asText(qresults);
// QueryExecUtils.executeQuery(q, qexec);
// searchResultsLabels=QueryExecUtils.executeQuery(q, qexec)+"";
} finally {
dataset.end();
}
return queryResults;
}
public static void queryDataComment(Dataset dataset, String kw) {
String queryString = "PREFIX : <http://example/>" + "PREFIX text: <http://jena.apache.org/text#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "SELECT * " + " { "
+ "?s text:query (rdfs:comment '" + kw + "') ;" + " rdfs:comment ?comment" + " } limit 10";
dataset.begin(ReadWrite.READ);
try {
Query q = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
QueryExecUtils.executeQuery(q, qexec);
} finally {
dataset.end();
}
}
}
Copyright 2019 ETSI
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
Options -MultiViews
RewriteEngine on
DirectorySlash Off
# internal redirects for core
# redirects core to core/v3.1.1/core
RewriteRule ^core$ /core/v3.1.1/core
# redirects core/example to core/v3.1.1/example
# redirects core/example/ to core/v3.1.1/example
RewriteRule ^core/example/?$ /core/v3.1.1/example
# redirects core/v1.1.1 to core/v1.1.1/core
RewriteRule ^core/v([0-9]+)\.([0-9]+)\.([0-9]+)/?$ /core/v$1.$2.$3/core
# redirects core/v1.1.1.ttl to core/v1.1.1/core.ttl
RewriteRule ^core/v([0-9]+)\.([0-9]+)\.([0-9]+)\.([^\./]+)$ /core/v$1.$2.$3/core.$4 [R=302,NE]
# redirects core.ttl to core/v3.1.1/core.ttl
RewriteRule ^core\.([^\./]*)$ /core/v3.1.1/core.$1 [R=302,NE]
# internal redirects for sarefabcd
# redirects saref4ener to saref4ener/latest/saref4ener
RewriteRule ^(saref[^\./]*)$ /$1/latest/$1
# redirects saref4ener/latest to saref4ener/latest/saref4ener
# redirects saref4ener/latest/ to saref4ener/latest/saref4ener
RewriteRule ^(saref[^\./]*)/latest/?$ /$1/latest/$1
# redirects saref4ener/example to saref4ener/latest/example
# redirects saref4ener/example/ to saref4ener/latest/example
RewriteRule ^(saref[^\./]*)/example/?$ /$1/latest/example
# redirects saref4ener/v1.1.1 to saref4ener/v1.1.1/saref4ener
# redirects saref4ener/v1.1.1/ to saref4ener/v1.1.1/saref4ener
RewriteRule ^(saref[^\./]*)/v([0-9]+)\.([0-9]+)\.([0-9]+)/?$ /$1/v$2.$3.$4/$1
# redirects saref4ener/latest.ttl to saref4ener/latest/saref4ener.ttl
RewriteRule ^(saref[^\./]*)/latest\.([^\./]+)$ /$1/latest/$1.$2 [R=302,NE]
# redirects saref4ener/v1.1.1.ttl to saref4ener/v1.1.1/saref4ener.ttl
RewriteRule ^(saref[^\./]*)/v([0-9]+)\.([0-9]+)\.([0-9]+)\.([^\./]+)$ /$1/v$2.$3.$4/$1.$5 [R=302,NE]
# redirects saref4ener.ttl to saref4ener/latest/saref4ener.ttl
RewriteRule ^(saref[^\./]*)\.([^\./]*)$ /$1/latest/$1.$2 [R=302,NE]
# Main
# internal redirects for core
# redirects core/bbb/core to core/bbb/core.html
RewriteCond %{HTTP_ACCEPT} !(application/rdf\+xml|text/turtle|text/n3)
RewriteRule ^core/([^/]+)/core$ /core/$1/core.html [R=302,NE]
# redirects core/bbb/core to core/bbb/core.rdf
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^core/([^/]+)/core$ /core/$1/core.rdf [R=302,NE]
# redirects core/bbb/core to core/bbb/core.ttl
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^core/([^/]+)/core$ /core/$1/core.ttl [R=302,NE]
# redirects core/bbb/core to core/bbb/core.n3
RewriteCond %{HTTP_ACCEPT} text/n3
RewriteRule ^core/([^/]+)/core$ /core/$1/core.n3 [R=302,NE]
# internal redirects for sarefabcd
# redirects sarefaaa/bbb/sarefccc to sarefaaa/bbb/sarefccc.html
RewriteCond %{HTTP_ACCEPT} !(application/rdf\+xml|text/turtle|text/n3)
RewriteRule ^(saref[^\./]*)/([^/]+)/(saref[^\./]*)$ /$1/$2/$3.html [R=302,NE]
# redirects sarefaaa/bbb/sarefccc to sarefaaa/bbb/sarefccc.rdf
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^(saref[^\./]*)/([^/]+)/(saref[^\./]*)$ /$1/$2/$3.rdf [R=302,NE]
# redirects sarefaaa/bbb/sarefccc to sarefaaa/bbb/sarefccc.ttl
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^(saref[^\./]*)/([^/]+)/(saref[^\./]*)$ /$1/$2/$3.ttl [R=302,NE]
# redirects sarefaaa/bbb/sarefccc to sarefaaa/bbb/sarefccc.n3
RewriteCond %{HTTP_ACCEPT} text/n3
RewriteRule ^(saref[^\./]*)/([^/]+)/(saref[^\./]*)$ /$1/$2/$3.n3 [R=302,NE]
# examples
# redirects core/bbb/example to core/bbb/example.ttl
RewriteRule ^core/([^/]+)/example$ /core/$1/example.ttl [R=302,NE]
# redirects sarefaaa/bbb/example to sarefaaa/bbb/example.ttl
RewriteRule ^(saref[^\./]*)/([^/]+)/example$ /$1/$2/example.ttl [R=302,NE]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head>
<body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource could not be found on this server.</p>
Available variants:<ul><li><a href="index-en.html">html</a></li><li><a href="ontology.json">JSON-LD</a></li><li><a href="ontology.xml">RDF/XML</a></li><li><a href="ontology.nt">N-Triples</a></li><li><a href="ontology.ttl">TTL</a></li></ul>
</body></html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment