Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Commit 3114ad8

Browse files
Merge pull request #5 from SANSA-Stack/feature/scalastyle-plugin
Feature/scalastyle plugin
2 parents aca945a + b10c81e commit 3114ad8

File tree

40 files changed

+280
-301
lines changed

40 files changed

+280
-301
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ project/plugins/project/
1717
.worksheet
1818
*.iml
1919
.idea
20+
21+
scalastyle-output.xml

pom.xml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<CodeCacheSize>512m</CodeCacheSize>
8383
<gpg.keyname>AKSW</gpg.keyname>
8484
<owlapi.version>5.1.3</owlapi.version>
85+
<scalastyle.config.path>${project.basedir}/scalastyle-config.xml</scalastyle.config.path>
8586
</properties>
8687

8788
<prerequisites>
@@ -520,30 +521,33 @@
520521
<groupId>com.versioneye</groupId>
521522
<artifactId>versioneye-maven-plugin</artifactId>
522523
</plugin>
523-
<!--<plugin>-->
524-
<!--<groupId>org.scalastyle</groupId>-->
525-
<!--<artifactId>scalastyle-maven-plugin</artifactId>-->
526-
<!--<version>0.8.0</version>-->
527-
<!--<configuration>-->
528-
<!--<verbose>false</verbose>-->
529-
<!--<failOnViolation>false</failOnViolation>-->
530-
<!--<includeTestSourceDirectory>false</includeTestSourceDirectory>-->
531-
<!--<failOnWarning>false</failOnWarning>-->
532-
<!--<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>-->
533-
<!--<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>-->
534-
<!--<configLocation>scalastyle-config.xml</configLocation>-->
535-
<!--<outputFile>${basedir}/target/scalastyle-output.xml</outputFile>-->
536-
<!--<inputEncoding>${project.build.sourceEncoding}</inputEncoding>-->
537-
<!--<outputEncoding>${project.reporting.outputEncoding}</outputEncoding>-->
538-
<!--</configuration>-->
539-
<!--<executions>-->
540-
<!--<execution>-->
541-
<!--<goals>-->
542-
<!--<goal>check</goal>-->
543-
<!--</goals>-->
544-
<!--</execution>-->
545-
<!--</executions>-->
546-
<!--</plugin>-->
524+
525+
<!-- Scalastyle -->
526+
<plugin>
527+
<groupId>org.scalastyle</groupId>
528+
<artifactId>scalastyle-maven-plugin</artifactId>
529+
<version>1.0.0</version>
530+
<configuration>
531+
<verbose>false</verbose>
532+
<failOnViolation>false</failOnViolation>
533+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
534+
<failOnWarning>false</failOnWarning>
535+
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
536+
<testSourceDirectory>${project.basedir}/src/test/scala</testSourceDirectory>
537+
<!-- we use a central config located in the root directory -->
538+
<configLocation>${scalastyle.config.path}</configLocation>
539+
<outputFile>${project.basedir}/scalastyle-output.xml</outputFile>
540+
<outputEncoding>UTF-8</outputEncoding>
541+
</configuration>
542+
<executions>
543+
<execution>
544+
<goals>
545+
<goal>check</goal>
546+
</goals>
547+
</execution>
548+
</executions>
549+
</plugin>
550+
547551
</plugins>
548552
</build>
549553

@@ -668,6 +672,7 @@
668672

669673
<!-- the profile used for deployment to Sonatype Maven repository -->
670674
<profile>
675+
<!-- for Maven Central deployment -->
671676
<id>ossrh</id>
672677
<distributionManagement>
673678
<repository>
@@ -786,5 +791,18 @@
786791
</plugins>
787792
</build>
788793
</profile>
794+
795+
<!-- for Scalastyle plugin -->
796+
<profile>
797+
<id>root-dir</id>
798+
<activation>
799+
<file>
800+
<exists>${project.basedir}/../../scalastyle-config.xml</exists>
801+
</file>
802+
</activation>
803+
<properties>
804+
<scalastyle.config.path>${project.basedir}/../scalastyle-config.xml</scalastyle.config.path>
805+
</properties>
806+
</profile>
789807
</profiles>
790808
</project>

sansa-inference-common/src/main/scala/net/sansa_stack/inference/data/JenaOps.scala

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package net.sansa_stack.inference.data
22

3+
import scala.collection.JavaConverters._
4+
35
import org.apache.jena.datatypes.{BaseDatatype, RDFDatatype, TypeMapper}
46
import org.apache.jena.graph.{Graph => JenaGraph, Node => JenaNode, Triple => JenaTriple, _}
5-
import org.apache.jena.rdf.model.{Literal => JenaLiteral, Seq => _}
6-
7-
import scala.collection.JavaConverters._
7+
import org.apache.jena.rdf.model.{Seq => _}
88

99
class JenaOps extends RDFOps[Jena] {
1010

@@ -33,10 +33,12 @@ class JenaOps extends RDFOps[Jena] {
3333
val s = t.getSubject
3434
val p = t.getPredicate
3535
val o = t.getObject
36-
if (p.isInstanceOf[Jena#URI])
37-
(s, p.asInstanceOf[Jena#URI], o)
38-
else
39-
throw new RuntimeException("fromTriple: predicate " + p.toString + " must be a URI")
36+
p match {
37+
case uri: Node_URI =>
38+
(s, uri, o)
39+
case _ =>
40+
throw new RuntimeException("fromTriple: predicate " + p.toString + " must be a URI")
41+
}
4042
}
4143

4244
// node
@@ -52,10 +54,11 @@ class JenaOps extends RDFOps[Jena] {
5254
def makeUri(iriStr: String): Jena#URI = { NodeFactory.createURI(iriStr).asInstanceOf[Node_URI] }
5355

5456
def fromUri(node: Jena#URI): String =
55-
if (node.isURI)
57+
if (node.isURI) {
5658
node.getURI
57-
else
59+
} else {
5860
throw new RuntimeException("fromUri: " + node.toString() + " must be a URI")
61+
}
5962

6063
// bnode
6164

@@ -67,17 +70,18 @@ class JenaOps extends RDFOps[Jena] {
6770
}
6871

6972
def fromBNode(bn: Jena#BNode): String =
70-
if (bn.isBlank)
73+
if (bn.isBlank) {
7174
bn.getBlankNodeId.getLabelString
72-
else
75+
} else {
7376
throw new RuntimeException("fromBNode: " + bn.toString + " must be a BNode")
77+
}
7478

7579
// literal
7680

7781
// TODO the javadoc doesn't say if this is thread safe
7882
lazy val mapper = TypeMapper.getInstance
7983

80-
def jenaDatatype(datatype: Jena#URI) = {
84+
private def jenaDatatype(datatype: Jena#URI) = {
8185
val iriString = fromUri(datatype)
8286
val typ = mapper.getTypeByName(iriString)
8387
if (typ == null) {
@@ -94,20 +98,21 @@ class JenaOps extends RDFOps[Jena] {
9498
val __rdfLangStringURI: Jena#URI = makeUri("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")
9599

96100
def makeLiteral(lexicalForm: String, datatype: Jena#URI): Jena#Literal =
97-
if (datatype == __xsdStringURI)
101+
if (datatype == __xsdStringURI) {
98102
NodeFactory.createLiteral(lexicalForm, null, null).asInstanceOf[Node_Literal]
99-
else
103+
} else {
100104
NodeFactory.createLiteral(lexicalForm, null, jenaDatatype(datatype)).asInstanceOf[Node_Literal]
105+
}
101106

102107
def makeLangTaggedLiteral(lexicalForm: String, lang: Jena#Lang): Jena#Literal =
103108
NodeFactory.createLiteral(lexicalForm, fromLang(lang), null).asInstanceOf[Node_Literal]
104109

105110

106111
// lang
107112

108-
def makeLang(langString: String) = langString
113+
def makeLang(langString: String): String = langString
109114

110-
def fromLang(lang: Jena#Lang) = lang
115+
def fromLang(lang: Jena#Lang): String = lang
111116

112117

113118

sansa-inference-common/src/main/scala/net/sansa_stack/inference/data/RDF.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ trait RDF {
3939
// types for the graph traversal API
4040
type NodeMatch
4141
type NodeAny <: NodeMatch
42-
}
42+
}

sansa-inference-common/src/main/scala/net/sansa_stack/inference/data/RDFTuple.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package net.sansa_stack.inference.data
88
* @author Lorenz Buehmann
99
*/
1010
case class RDFTuple(s: String, o: String) extends Product2[String, String] {
11-
override def _1: String = s
12-
override def _2: String = o
13-
}
11+
override def _1: String = s
12+
13+
override def _2: String = o
14+
}

sansa-inference-common/src/main/scala/net/sansa_stack/inference/data/SimpleRDFOps.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class SimpleRDFOps extends RDFOps[SimpleRDF] {
1717
val s = t.s
1818
val p = t.p
1919
val o = t.o
20-
if (p.isInstanceOf[SimpleRDF#URI])
21-
(s, p.asInstanceOf[SimpleRDF#URI], o)
22-
else
23-
throw new RuntimeException("fromTriple: predicate " + p.toString + " must be a URI")
20+
p match {
21+
case uri: String =>
22+
(s, uri, o)
23+
case _ =>
24+
throw new RuntimeException("fromTriple: predicate " + p.toString + " must be a URI")
25+
}
2426
}
2527

2628
// node

sansa-inference-common/src/main/scala/net/sansa_stack/inference/rules/minimizer/MinimizationRule.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ abstract class MinimizationRule extends Logging {
1818

1919
def apply(graph: RuleDependencyGraph): RuleDependencyGraph
2020

21-
}
21+
}

sansa-inference-common/src/main/scala/net/sansa_stack/inference/rules/plan/SimplePlanGenerator.scala

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
package net.sansa_stack.inference.rules.plan
22

3-
import java.io.PrintWriter
4-
import java.util.Collections
3+
import scala.collection.JavaConverters._
4+
import scala.util.Try
55

6-
import com.google.common.collect.ImmutableList
76
import org.apache.calcite.config.Lex
7+
import org.apache.calcite.interpreter.{BindableConvention, Bindables}
88
import org.apache.calcite.plan.{RelOptUtil, _}
9+
import org.apache.calcite.rel.`type`.RelDataTypeSystem
10+
import org.apache.calcite.rel.rules._
911
import org.apache.calcite.rel.{RelCollationTraitDef, RelNode}
1012
import org.apache.calcite.schema.SchemaPlus
1113
import org.apache.calcite.sql.parser.SqlParser
1214
import org.apache.calcite.tools._
13-
import collection.JavaConverters._
14-
import scala.util.Try
15-
16-
import org.apache.calcite.rel.`type`.RelDataTypeSystem
17-
import org.apache.calcite.rel.externalize.RelWriterImpl
18-
import org.apache.calcite.rel.rules._
1915
import org.apache.jena.reasoner.rulesys.Rule
2016

2117
import net.sansa_stack.inference.utils.{Logging, RuleUtils}
22-
import org.apache.calcite.adapter.enumerable.{EnumerableConvention, EnumerableRules}
23-
import org.apache.calcite.interpreter.{BindableConvention, Bindables}
24-
import org.apache.calcite.plan.RelOptPlanner.CannotPlanException
25-
import org.apache.calcite.plan.hep.{HepMatchOrder, HepPlanner, HepProgramBuilder}
26-
import org.apache.calcite.plan.volcano.VolcanoPlanner
27-
import org.apache.calcite.sql2rel.{RelDecorrelator, SqlToRelConverter}
2818

2919
/**
3020
* @author Lorenz Buehmann
@@ -37,7 +27,7 @@ class SimplePlanGenerator(schema: SchemaPlus) extends Logging {
3727
BindableConvention.INSTANCE.getTraitDef
3828
)
3929

40-
val optRuleSet = RuleSets.ofList(
30+
val optRuleSet: RuleSet = RuleSets.ofList(
4131
FilterJoinRule.FILTER_ON_JOIN,// push a filter into a join
4232
FilterJoinRule.JOIN,// push filter into the children of a join
4333
ProjectJoinTransposeRule.INSTANCE// push a projection to the children of a join
@@ -68,13 +58,13 @@ class SimplePlanGenerator(schema: SchemaPlus) extends Logging {
6858
// // Context provides a way to store data within the planner session that can be accessed in planner rules.
6959
// .context(Contexts.EMPTY_CONTEXT)
7060
// // Rule sets to use in transformation phases. Each transformation phase can use a different set of rules.
71-
//// .ruleSets(optRuleSet)
61+
// // .ruleSets(optRuleSet)
7262
// .ruleSets(RuleSets.ofList(Bindables.BINDABLE_TABLE_SCAN_RULE, Bindables.BINDABLE_PROJECT_RULE, Bindables.BINDABLE_JOIN_RULE, Bindables.BINDABLE_FILTER_RULE, FilterJoinRule.FILTER_ON_JOIN))
7363
// .programs(Programs.ofRules(Bindables.BINDABLE_TABLE_SCAN_RULE, Bindables.BINDABLE_PROJECT_RULE, Bindables.BINDABLE_JOIN_RULE, Bindables.BINDABLE_FILTER_RULE, FilterJoinRule.FILTER_ON_JOIN))
7464
//
7565
// // Custom cost factory to use during optimization
7666
// .costFactory(null)
77-
//// .programs(program)
67+
// // .programs(program)
7868
// .typeSystem(RelDataTypeSystem.DEFAULT)
7969
// .build()
8070

sansa-inference-common/src/main/scala/net/sansa_stack/inference/utils/JenaTripleToNTripleString.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.apache.jena.graph.Triple
99
* @author Lorenz Buehmann
1010
*/
1111
class JenaTripleToNTripleString
12-
extends ((Triple) => String)
12+
extends Function[Triple, String]
1313
with java.io.Serializable {
1414
override def apply(t: Triple): String = {
1515
val subStr =
@@ -27,7 +27,7 @@ class JenaTripleToNTripleString
2727
} else {
2828
s"<${t.getObject}>"
2929
}
30-
s"${subStr} <${t.getPredicate}> ${objStr} ."
30+
s"$subStr <${t.getPredicate}> $objStr ."
3131
}
3232
}
3333

sansa-inference-common/src/main/scala/net/sansa_stack/inference/utils/Logging.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.language.implicitConversions
1111
*/
1212
trait Logging {
1313

14-
@transient private var log_ : Logger = null
14+
@transient private var log_ : Logger = _
1515

1616
// Method to get or create the logger for this object
1717
protected def log: Logger = {
@@ -22,7 +22,7 @@ trait Logging {
2222
}
2323

2424
// Method to get the logger name for this object
25-
protected def logName = {
25+
protected def logName: String = {
2626
// Ignore trailing $'s in the class names for Scala objects
2727
this.getClass.getName.stripSuffix("$")
2828
}

0 commit comments

Comments
 (0)