Commit 539b484e authored by mihaidascalu's avatar mihaidascalu

#16 Refactoring of packages

parent 863053c9
......@@ -6,7 +6,7 @@
<groupId>com.readerbench</groupId>
<artifactId>${artifactory.id}</artifactId>
<version>3.0.3</version>
<version>3.0.4</version>
<packaging>jar</packaging>
<properties>
......
......@@ -15,7 +15,7 @@
*/
package com.readerbench.dao;
import com.readerbench.utils.App;
import com.readerbench.services.commons.ReadPropertiesFile;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
......@@ -38,7 +38,7 @@ public class DAOService {
private static final Object lock = new Object();
private DAOService() {
Properties p = App.getProperties("db.properties");
Properties p = ReadPropertiesFile.getProperties("db.properties");
emf = Persistence.createEntityManagerFactory("ReaderBench", p);
em = emf.createEntityManager();
}
......
......@@ -3,8 +3,9 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.readerbench.utils;
package com.readerbench.services.commons;
import com.readerbench.services.complexity.IndexLevel;
import com.readerbench.data.AbstractDocument;
import com.readerbench.data.AnalysisElement;
import com.readerbench.data.Block;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.readerbench.utils;
package com.readerbench.services.commons;
import java.util.ResourceBundle;
......
package com.readerbench.utils;
package com.readerbench.services.commons;
import java.io.IOException;
import java.io.InputStream;
......@@ -7,7 +7,7 @@ import java.util.Properties;
/**
* Created by dorinela on 28.11.2017.
*/
public class App {
public class ReadPropertiesFile {
/**
* read data from .properties files
......@@ -20,7 +20,7 @@ public class App {
InputStream input;
try {
input = new App().getClass().getClassLoader().getResourceAsStream(resourceName);
input = new ReadPropertiesFile().getClass().getClassLoader().getResourceAsStream(resourceName);
if (input == null) {
throw new RuntimeException("Configuration file missing: " + resourceName);
}
......
......@@ -7,8 +7,7 @@ package com.readerbench.services.complexity;
import com.readerbench.data.AbstractDocument;
import com.readerbench.data.AnalysisElement;
import com.readerbench.utils.Functions;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.commons.Functions;
import java.util.function.Function;
import java.util.stream.Stream;
......
/*
* Copyright 2016 ReaderBench.
*
* 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 com.readerbench.services.complexity;
/**
*
* @author stefan
*/
public enum IndexLevel {
BLOCK,
SENTENCE,
DOC
}
......@@ -30,7 +30,7 @@ import com.readerbench.services.complexity.cohesion.lexicalChains.LexicalChainsC
import com.readerbench.services.complexity.cohesion.lexicalChains.LexicalChainsMaxSpan;
import com.readerbench.services.complexity.cohesion.semantic.*;
import com.readerbench.services.semanticModels.SimilarityType;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.util.ArrayList;
import java.util.List;
......
......@@ -20,7 +20,7 @@ import com.readerbench.data.AnalysisElement;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -21,7 +21,7 @@ import com.readerbench.services.commons.DoubleStatistics;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.AbstractDocument;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.util.Map;
......
......@@ -20,7 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.AbstractDocument;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.AbstractDocument;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -20,7 +20,7 @@ import com.readerbench.services.commons.DoubleStatistics;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -20,7 +20,7 @@ import com.readerbench.services.commons.DoubleStatistics;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.AbstractDocument;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndices;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.util.Map;
......
......@@ -11,7 +11,7 @@ import edu.stanford.nlp.util.StringUtils;
import org.openide.util.Exceptions;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.io.*;
import java.util.*;
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.Lang;
import com.readerbench.services.complexity.ComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.services.complexity.ComplexityIndicesFactory;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
......
......@@ -10,7 +10,7 @@ import com.readerbench.data.AnalysisElement;
import com.readerbench.data.sentiment.SentimentValence;
import com.readerbench.services.complexity.AbstractComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
/**
*
......
......@@ -11,7 +11,7 @@ import com.readerbench.data.sentiment.SentimentValence;
import com.readerbench.services.complexity.ComplexityIndex;
import com.readerbench.services.complexity.ComplexityIndicesEnum;
import com.readerbench.services.complexity.ComplexityIndicesFactory;
import com.readerbench.utils.IndexLevel;
import com.readerbench.services.complexity.IndexLevel;
import java.util.ArrayList;
import java.util.List;
......
......@@ -19,7 +19,7 @@ import com.readerbench.data.AbstractDocument;
import com.readerbench.data.Block;
import com.readerbench.data.Sentence;
import com.readerbench.data.discourse.SemanticCohesion;
import com.readerbench.utils.DoubleStatistics;
import com.readerbench.services.commons.DoubleStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -96,7 +96,7 @@ public class CohesionGraph {
DoubleStatistics statistics = IntStream.range(0, d.getBlocks().size() - 1).parallel()
.mapToObj(i -> i)
.flatMap(i -> IntStream.range(i + 1, d.getBlocks().size())
.mapToObj(j -> d.getBlockDistances()[i][j]))
.mapToObj(j -> d.getBlockDistances()[i][j]))
.filter(Objects::nonNull)
.map(SemanticCohesion::getCohesion)
.collect(DoubleStatistics.collector());
......@@ -106,7 +106,7 @@ public class CohesionGraph {
avg = statistics.getAverage();
stdev = statistics.getStandardDeviation();
}
// prune initial graph, but always keep adjacent pairs of blocks or explicitly referred blocks
// iterate through all pairs of blocks of the document
for (int i = 0; i < d.getBlocks().size() - 1; i++) {
......@@ -181,7 +181,7 @@ public class CohesionGraph {
statistics = IntStream.range(0, b.getSentences().size() - 1).parallel()
.mapToObj(i -> i)
.flatMap(i -> IntStream.range(i + 1, b.getSentences().size())
.mapToObj(j -> b.getSentenceDistances()[i][j]))
.mapToObj(j -> b.getSentenceDistances()[i][j]))
.filter(Objects::nonNull)
.map(SemanticCohesion::getCohesion)
.collect(DoubleStatistics.collector());
......
......@@ -29,7 +29,7 @@ import com.readerbench.services.commons.VectorAlgebra;
import com.readerbench.services.nlp.stemmer.Stemmer;
import com.readerbench.services.semanticModels.ISemanticModel;
import com.readerbench.services.semanticModels.SimilarityType;
import com.readerbench.thrift.Word2VecService;
import com.readerbench.services.thrift.Word2VecService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -4,7 +4,7 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package com.readerbench.thrift;
package com.readerbench.services.thrift;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
/*
* Copyright 2016 ReaderBench.
*
* 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 com.readerbench.utils;
import java.util.DoubleSummaryStatistics;
import java.util.stream.Collector;
/**
*
* @author Stefan Ruseti
*/
public class DoubleStatistics extends DoubleSummaryStatistics {
private double sumOfSquare = 0.0d;
private double sumOfSquareCompensation; // Low order bits of sum
private double simpleSumOfSquare; // Used to compute right sum for non-finite inputs
@Override
public void accept(double value) {
super.accept(value);
double squareValue = value * value;
simpleSumOfSquare += squareValue;
sumOfSquareWithCompensation(squareValue);
}
public DoubleStatistics combine(DoubleStatistics other) {
super.combine(other);
simpleSumOfSquare += other.simpleSumOfSquare;
sumOfSquareWithCompensation(other.sumOfSquare);
sumOfSquareWithCompensation(other.sumOfSquareCompensation);
return this;
}
private void sumOfSquareWithCompensation(double value) {
double tmp = value - sumOfSquareCompensation;
double velvel = sumOfSquare + tmp; // Little wolf of rounding error
sumOfSquareCompensation = (velvel - sumOfSquare) - tmp;
sumOfSquare = velvel;
}
public double getSumOfSquare() {
double tmp = sumOfSquare + sumOfSquareCompensation;
if (Double.isNaN(tmp) && Double.isInfinite(simpleSumOfSquare)) {
return simpleSumOfSquare;
}
return tmp;
}
public final double getStandardDeviation() {
return getStandardDeviation(0);
}
public final double getStandardDeviation(double orElse) {
long count = getCount();
double _sumOfSquare = getSumOfSquare();
double average = getAverage();
if (count == 0) return orElse;
return count > 1 ? Math.sqrt((_sumOfSquare - count * Math.pow(average, 2)) / (count - 1)) : 0.;
}
public static Collector<Double, ?, DoubleStatistics> collector() {
return Collector.of(DoubleStatistics::new, DoubleStatistics::accept, DoubleStatistics::combine);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.readerbench.utils;
/**
*
* @author stefan
*/
public enum IndexLevel {
BLOCK,
SENTENCE,
DOC
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment