Pellet Jena and OWL API Sparql query labels - jena

I'm using Pellet with OWL API in order to populate the ontologies and Jena to make some query. The problem is that I don't obtain results when querying for labels. My Code is:
reasoner=PelletReasonerFactory.getInstance().createReasoner
KnowledgeBase kb = reasoner.getKB();
PelletInfGraph graph = new org.mindswap.pellet.jena.PelletReasoner().bind( kb );
InfModel model = ModelFactory.createInfModel( graph );
Query q = QueryFactory.create(query );
QueryExecution qe = QueryExecutionFactory.create( q, model );
ResultSet rs = qe.execSelect();
ResultSetFormatter.out( rs );
If I ask for a label, for example using
Select ?x ?y
WHERE { ?x rdfs:label ?y.}
I obtain an empty string as label. The query works in protegè giving the labels requested. Any suggestion?
A snippet of the ontology:
<Thing rdf:about="onto.owl#Erba">
<rdf:type rdf:resource="http://linkedgeodata.org/ontology/Municipality"/>
<rdf:type rdf:resource="http://linkedgeodata.org/ontology/Place"/>
<rdf:type rdf:resource="onto.owl#Comune"/>
<rdf:type rdf:resource="onto.owl#Localizzazione"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Erba</rdfs:label>
<Locations:haLocalizzazione rdf:resource="onto.owl#Italia"/>
<Locations:haLocalizzazione rdf:resource="onto.owl#Como"/>
<Locations:haLocalizzazione rdf:resource="onto.owl#Lombardia"/>
<Locations:haProvincia rdf:resource="onto.owl#Como"/>
</Thing>
Here the maven pom file of the project:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20141113</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>pellet-profiler-ignazio1977</artifactId>
<version>2.4.0-ignazio1977</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>

Related

OpenApi hide a model property in the request

I know we can use this #ApiModelProperty annotation from this link to hide an id from the request when we use Swagger-Ui
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
But I am using this spring doc OpenApi dependency
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.32</version>
</dependency>
I am not getting this annotation #ApiModelProperty when I used springdoc-openapi-ui. What could be the annotation for this?
You have to replace swagger 2 annotations with swagger 3 annotations (it is already included with springdoc-openapi-ui dependency). Package for swagger 3 annotations is io.swagger.v3.oas.annotations.
It's all explained here:
https://springdoc.org/migrating-from-springfox.html

Type grid does not have type parameters

I began to study Vaadin and wrote the code as stated in the tutorial:
List<PatientEntity> personList = new ArrayList<>();
Grid<PatientEntity> grid = new Grid<>(PatientEntity.class);
I got errors in the second line
Type 'com.vaadin.ui.Grid' does not have type parameters" () and "Diamond operator is not applicable for non-parametrized types" (<>)
Dependencies from pom.xml:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>13.0.11</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
Type 'com.vaadin.ui.Grid' does not have type parameters
This is not the correct package. I think this is the grid from Vaadin 8. Try com.vaadin.flow.component.grid.Grid
Edit: adding #Tazavoo's comment into my answer, as it might very well solve your problem.
Have you added a Vaadin dependency to your pom.xml? Adding it to <dependencyManagement> does not actually add it as a dependency. You should keep the vaadin-bom there, as it will control the versions, but move vaadin-core to your actual <dependencies> tag.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>13.0.11</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
</dependencies>
With this pom structure your IDE should automatically suggest the correct Grid import to you (after you remove the incorrect import statement of course)
I'm not sure but you should try to remove the PatientEntity.class from the constructor
(as in the second exemple of vaadin)

Swagger-ui doesn't provide how i pass MediaType.APPLICATION_OCTET_STREAM content

Actually i am facing a problem that Swagger-ui can't show me input for MediaType.APPLICATION_OCTET_STREAM, so lets imagine this next service:
#PUT
#Path("/performAudioQuery")
#Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response performAudioQuery(InputStream audioInputStream){
//Impl of the service
}
and here are the dependencies
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
and i am using wildfly 9.x
So what should i do to make it possible for Swagger-ui working good with this previous service?
The current version of the Swagger/OpenAPI specification (2.0) doesn't deal kindly with file uploads as what's known as body parameter. We've formulated a workable solution that is covered at https://github.com/OAI/OpenAPI-Specification/issues/50 - however that solution is currently not fully supported by swagger-core and not supported at all in swagger-ui.

primefaces graphicImage f:param doesn't work [duplicate]

This question already has answers here:
Display dynamic image from database or remote source with p:graphicImage and StreamedContent
(4 answers)
Closed 7 years ago.
I have JSF:
<p:graphicImage value="#{chatView.userPhoto}">
<f:param name="userId" value="#{user.id}"/>
</p:graphicImage>
user.id is valid I have checked.
And bean:
#ManagedBean
#ViewScoped
public class ChatView extends BaseView {
/*
* Injecting managed beans in each other
* http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#InjectingManagedBeansInEachOther
*/
#ManagedProperty("#{chatUsers}")
private ChatUsers users;
public StreamedContent getUserPhoto() {
// there output is {}
System.out.println(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap());
return new DefaultStreamedContent();
}
}
But I have empty map in debug output for requestParameterMap. Any idea why?
UPDATED:
I created a simple project with such pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>grim</groupId>
<artifactId>grim</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jboss.bom>9.0.0.CR1</version.jboss.bom>
<version.primefaces>5.2</version.primefaces>
<version.atmosphere>2.3.1</version.atmosphere>
<version.jboss.logging>3.2.1.Final</version.jboss.logging>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-wildfly-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss WildFly -->
<!-- Import the CDI API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss WildFly -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<scope>provided</scope>
</dependency>
<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as #Email -->
<!-- Hibernate Validator is shipped in JBoss WildFly -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Annotation processor that raising compilation errors whenever constraint
annotations are incorrectly used. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<scope>provided</scope>
</dependency>
<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<!-- Import the Servlet API, we use provided scope as the API is included in JBoss WildFly. -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!--PrimeFaces-->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${version.primefaces}</version>
</dependency>
<!--Atmosphere-->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>${version.atmosphere}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Jboss Logging-->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${version.jboss.logging}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
View:
#ManagedBean
#ViewScoped
public class TestView {
public StreamedContent getImg() {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL.
return new DefaultStreamedContent();
}
else {
// So, browser is requesting the image. Return a real StreamedContent with the image bytes.
String studentId = context.getExternalContext().getRequestParameterMap().get("shashistId");
Shashist student = shashistService.find(Long.valueOf(studentId));
return new DefaultStreamedContent(new ByteArrayInputStream(student.getPhoto()));
}
}
}
And xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
<p:graphicImage value="#{testView.img}">
<f:param value="1" name="s"/>
</p:graphicImage>
</f:view>
</html>
But anyway I get empty request parameter map in debug output.
Thank to this answer https://stackoverflow.com/a/25425111/836701 I found the solution. The problem was in #ViewScope it should be #SessionScope for getting parameters from f:param.

Struts 2 submit form to one object

I have something similar to that:
class Model {
private String field1;
private String field2;
//setters
}
class Action extends ActionSupport {
private Model model;
public String execute() {
//breakpoint
}
public void setModel(Model model){
this.model=model;
}
}
on jsp:
<s:form id="addCommentForm" method="POST" namespace="%{namespace}" action="addComment">
<input type="text" name="model.field1"/>
<input type="text" name="model.field2"/>
</s:form>
When I submit this form unfortunately only 1 field in Model class is set.
I debug code and find that actually setters are called for both fields (field1 and field2), but for different instances of Model class.
So it appears, that it executes with next steps when form is submitteed:
create new instance (instance1) of Model class, set this instance in Action class
set field1 to instance1
create new instance (instance2) of Model class, set this instance in Action class
set field2 to instance2
So as I see instanse2 replace instance1.
I need field1 and field2 in one instance of Model class.
What need to be modified?
list of dependenced:
<dependency>
<groupId>com.vercer.engine.persist</groupId>
<artifactId>twig-persist</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.19</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1-6.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.1.8</version>
</dependency>
For complex types you need both a getter and setter so Struts2 can manipulate the object correctly, otherwise it will not be able to get the existing instance and will be forced to create a new instance of Model (new Model().setWhatever()) as opposed to seeing a model already exists and doing (getModel().setWhatever()).

Resources