Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST metric "UsageOfNouns" extended with an OntologyService #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<name>QA82 Analyzer Server</name>
<build>
<finalName>qa82-analyzer-server</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -94,6 +99,19 @@
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>edu.mit.jwi</groupId>
<artifactId>edu.mit.jwi</artifactId>
<version>2.3.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/edu.mit.jwi_2.3.3.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>2.13.0</version>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*******************************************************************************/
package org.qa82.analyzer.core;

import java.util.Set;
import java.util.List;

/**
* A repository of information providers.
Expand All @@ -21,8 +21,8 @@
public interface InformationProviderRepository {

public abstract void setInformationProviders(
Set<InformationProvider> informationProviders);
List<InformationProvider> informationProviders);

public abstract Set<InformationProvider> getInformationProviders();
public abstract List<InformationProvider> getInformationProviders();

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
package org.qa82.analyzer.core.bean;


import com.google.common.collect.Sets;
import com.google.common.primitives.Booleans;
import org.qa82.analyzer.server.dto.InformationNeedDescriptionDto;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.qa82.analyzer.server.dto.InformationNeedDescriptionDto;

/**
* Represents a need for information. This includes the format of the expected
* information as well as a list of information types for the parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.qa82.analyzer.core.Information;
import org.qa82.analyzer.core.impl.BooleanInformation;
import org.qa82.analyzer.core.impl.Element;
import org.qa82.analyzer.core.impl.FloatInformation;
import org.qa82.analyzer.core.impl.StringInformation;
import org.qa82.analyzer.server.dto.InformationDto;

Expand Down Expand Up @@ -50,6 +51,8 @@ private Information convert(Class<? extends Information> classType, String value
return new BooleanInformation(Boolean.valueOf(value));
} else if (classType.equals(StringInformation.class)) {
return new StringInformation(value);
} else if (classType.equals(FloatInformation.class)) {
return new FloatInformation(Float.valueOf(value));
}
throw new RuntimeException("Cast of parameter failed. " + value + " can not be cast to " + classType + ".");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2014 Michael Gebhart ([email protected]).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Gebhart - initial idea and concept
*
*******************************************************************************/

package org.qa82.analyzer.core.impl;

/**
* Information with type float.
*
* @author Pascal Burkhardt
* @since 17.04.2015
*/
public class FloatInformation extends AbstractInformation {

private Float value;

public FloatInformation(Float value) {
super(/* type is */"float");
this.setValue(value);
}

@Override
public Object getValue() {
return value;
}

public void setValue(Float value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,52 @@

package org.qa82.analyzer.core.impl;

import java.util.HashSet;
import java.util.Set;
import java.util.LinkedList;
import java.util.List;

import org.qa82.analyzer.core.Analyzer;
import org.qa82.analyzer.core.InformationProvider;
import org.qa82.analyzer.core.InformationProviderRepository;
import org.qa82.analyzer.core.providers.common.String_IsNounProvider;
import org.qa82.analyzer.core.providers.java.JaxRs_ServiceMethodProvider;
import org.qa82.analyzer.core.providers.java.JaxRs_ServiceNameProvider;
import org.qa82.analyzer.core.providers.java.JaxRs_ServiceProvider;
import org.qa82.analyzer.core.providers.java.WebserviceNameProvider;
import org.qa82.analyzer.core.providers.java.rest.RestMetric_UsageOfNounProvider;

public class InformationProviderRepositoryImpl implements InformationProviderRepository {

private Set<InformationProvider> informationProviders = new HashSet<InformationProvider>();
/**
* Logically should be a set, but InformationProviders then must implement hashcode and equals
* or at least comparable for TreeSets.
* LinkedList is ok at this moment.
* Watch out! Add an informationprovider only once!
*/
private List<InformationProvider> informationProviders = new LinkedList<InformationProvider>();

public InformationProviderRepositoryImpl(Analyzer analyzer) {
informationProviders.add(new JaxRs_ServiceProvider(analyzer));
informationProviders.add(new JaxRs_ServiceNameProvider(analyzer));
informationProviders.add(new JaxRs_ServiceMethodProvider(analyzer));
informationProviders.add(new RestMetric_UsageOfNounProvider(analyzer));
informationProviders.add(new String_IsNounProvider(analyzer));
informationProviders.add(new WebserviceNameProvider(analyzer));
}

/* (non-Javadoc)
* @see org.qa82.analyzer.core.impl.InformationProviderRepository#setInformationProviders(java.util.Set)
*/
@Override
public void setInformationProviders(
Set<InformationProvider> informationProviders) {
List<InformationProvider> informationProviders) {
this.informationProviders = informationProviders;
}

/* (non-Javadoc)
* @see org.qa82.analyzer.core.impl.InformationProviderRepository#getInformationProviders()
*/
@Override
public Set<InformationProvider> getInformationProviders() {
public List<InformationProvider> getInformationProviders() {
return informationProviders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.qa82.analyzer.core.Analyzer;
Expand All @@ -33,7 +35,7 @@
*/
public class SimpleAnalyzer implements Analyzer {

private Set<InformationProvider> providers = new HashSet<InformationProvider>();
private List<InformationProvider> providers = new LinkedList<InformationProvider>();
private Project project;

public SimpleAnalyzer(Project project) {
Expand Down Expand Up @@ -86,7 +88,7 @@ public AnalyzerResult resolve(InformationType expectedInformation, ParameterList
*/
@Override
public void setProviders(Collection<InformationProvider> providers) {
this.providers = new HashSet<InformationProvider>(providers);
this.providers = new LinkedList<InformationProvider>(providers);
}

/*
Expand All @@ -107,7 +109,7 @@ public void addInformationProvider(InformationProvider informationProvider) {
* @see org.qa82.analyzer.core.impl.Analyzer#getInformationProviders()
*/
@Override
public Set<InformationProvider> getInformationProviders() {
public List<InformationProvider> getInformationProviders() {
return providers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.qa82.analyzer.core.providers.common;

import java.util.ArrayList;
import java.util.List;

import org.qa82.analyzer.core.Analyzer;
import org.qa82.analyzer.core.Information;
import org.qa82.analyzer.core.bean.InformationNeedDescription;
import org.qa82.analyzer.core.bean.InformationType;
import org.qa82.analyzer.core.bean.ParameterList;
import org.qa82.analyzer.core.impl.AbstractInformationProvider;
import org.qa82.analyzer.core.impl.BooleanInformation;
import org.qa82.analyzer.core.impl.StringInformation;
import org.qa82.analyzer.core.services.WordNetService;

/**
*
* This information provider checks if a given string is a noun or not.
*
* @author Pascal Burkhardt
* @since 17.04.2015
*/
public class String_IsNounProvider extends AbstractInformationProvider {

public String_IsNounProvider(Analyzer analyzer) {
super(analyzer);
}

@Override
public String getName() {
return "String.IsNoun";
}

@Override
public String getDescription() {
return "String.IsNoun";
}

@Override
public InformationNeedDescription getProvidedInformation() {
List<InformationType> acceptedInformationTypes = new ArrayList<InformationType>();
acceptedInformationTypes.add(new InformationType(StringInformation.class, null, null));
return new InformationNeedDescription(new InformationType(BooleanInformation.class, "stringIsNoun", this.getDescription()),
acceptedInformationTypes);
}

@Override
public List<Information> resolve(InformationType expectedInformation, ParameterList parameters) {
ArrayList<Information> informationList = new ArrayList<>();

for(Information param : parameters) {
if(param.getValue() != null && param.getValue() instanceof String) {
String name = param.getValue().toString();
informationList.add(new BooleanInformation(isNoun(name)));
}
}

return informationList;
}

private boolean isNoun(String word) {
if(word == null || isNotARegularWord(word)) {
return false;
}

return WordNetService.getInstance().isNoun(word);
}

private boolean isNotARegularWord(String word) {
return word.matches(".*[^a-zA-Z- ].*");
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package org.qa82.analyzer.core.providers.java;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.qa82.analyzer.core.Analyzer;
import org.qa82.analyzer.core.Information;
import org.qa82.analyzer.core.Repository;
import org.qa82.analyzer.core.bean.InformationNeedDescription;
import org.qa82.analyzer.core.bean.InformationType;
import org.qa82.analyzer.core.bean.ParameterList;
import org.qa82.analyzer.core.impl.AbstractInformationProvider;
import org.qa82.analyzer.core.impl.Element;
import org.qa82.analyzer.core.impl.StringInformation;
import org.qa82.analyzer.core.providers.java.parser.jaxrs.JaxRs_Compatibility;
import org.qa82.analyzer.core.providers.java.parser.jaxrs.JaxRs_Parser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* Created by Pascal Giessler on 10.12.2014.
*/
Expand All @@ -41,14 +40,14 @@ public String getDescription() {

@Override
public InformationNeedDescription getProvidedInformation() {
return new InformationNeedDescription(new InformationType(Element.class, "http://cos.ontoware.org/cos#web-service#name", this.getDescription()),
return new InformationNeedDescription(new InformationType(StringInformation.class, "http://qa82.com/ontologies/qa4swo.owl#resource#name#jaxrs", this.getDescription()),
new ArrayList<>());
}

@Override
public List<Information> resolve(InformationType expectedInformation, ParameterList parameters) {
ArrayList<Information> informationList = new ArrayList<>();

Set<Repository> repositories = this.analyzer.getProject().getRepositories();
for (Repository r : repositories) {
for (File javaFile : r.searchFileEndingWith("java")) {
Expand Down
Loading