Skip to content

Commit

Permalink
updating Maven CI + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GustikS committed Jul 9, 2020
1 parent 47e4b1b commit 6475a60
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 91 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Maven CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
12 changes: 6 additions & 6 deletions Algebra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.1</version>
<scope>test</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>org.junit.jupiter</groupId>-->
<!--<artifactId>junit-jupiter-api</artifactId>-->
<!--<version>5.6.1</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
</dependencies>


Expand Down
18 changes: 6 additions & 12 deletions CLI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.23</version>
<scope>test</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>org.openjdk.jmh</groupId>-->
<!--<artifactId>jmh-core</artifactId>-->
<!--<version>1.23</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cz.cvut.fel.ida.utils.generic.Utilities;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;

import java.io.File;
import java.io.IOException;
Expand All @@ -28,19 +29,22 @@ void tearDown() {
}

@TestAnnotations.Fast
@Disabled
void checkResourceFile() {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("relational").getFile());
LOG.fine(file.toString());
}

@TestAnnotations.Fast
@Disabled
void getResource() {
String tmp2 = Utilities.readResourceFile("dummy.txt");
LOG.fine(tmp2);
}

@TestAnnotations.Fast
@Disabled
public void listAvailableResources() {
boolean available = false;
Enumeration<URL> e = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cz.cvut.fel.ida.neuralogic.revised.unsorted;

import cz.cvut.fel.ida.utils.generic.TestAnnotations;
import sun.misc.Launcher;

import java.io.File;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void systemInfoTest() {
@TestAnnotations.Fast
public void jartest(){
String path = ".";
final URL url = Launcher.class.getResource("/" + path);
final URL url = UtilsTests.class.getResource("/" + path);
if (url != null) {
try {
final File apps = new File(url.toURI());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Generated from /home/gusta/googledrive/Github/NeuraLogic/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4 by ANTLR 4.8
package cz.cvut.fel.ida.logic.parsing.antlr;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class NeuralogicLexer extends Lexer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ predicateMetadata: predicate metadataList;
weightMetadata: DOLLAR ATOMIC_NAME metadataList;
templateMetadata: metadataList;

//weight: fixed_weight | SEPARATOR (INT | FLOAT) SEPARATOR;
//SEPARATOR: (' ' | BOL | EOF);

// weights may have identifiers for sharing
// weights may have identifiers for explicit sharing
weight: (DOLLAR ATOMIC_NAME ASSIGN)? (fixedValue | value);
fixedValue: LANGLE value RANGLE;
offset: weight;
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# NeuraLogic

![Generic badge](https://img.shields.io/badge/Release-0.2.1-blue.svg)
![Generic badge](https://img.shields.io/badge/Licence-MIT-green.svg)
![Generic badge](https://img.shields.io/badge/Java-1.8-orange.svg)
![Java CI with Maven](https://github.com/GustikS/NeuraLogic/workflows/Maven%20CI/badge.svg)
![GitHub licence](https://img.shields.io/github/license/gustiks/neuralogic)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/gustiks/neuralogic?include_prereleases)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/gustiks/neuralogic)
![GitHub top language](https://img.shields.io/github/languages/top/gustiks/neuralogic)


_NeuraLogic is a framework for combining **relational** and **deep** learning through a form of **differentiable logic programming**. It is an official implementation of the **[Lifted Relational Neural Networks](#papers)** concept._


---
At the core there is a custom language you can use to write differentiable programs encoding your learning scenarios, similarly to classic Deep Learning (DL) frameworks (e.g. TensorFlow). However, the language follows a [logic programming](https://en.wikipedia.org/wiki/Logic_programming) paradigm and is **declarative** in nature (it's similar to [Datalog](https://en.wikipedia.org/wiki/Datalog)). This means that instead of directly encoding the computation graph, you just declare:
At the core there is a custom [language](./Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4) you can use to write differentiable programs encoding your learning scenarios, similarly to classic Deep Learning (DL) frameworks (e.g. TensorFlow). However, the language follows a [logic programming](https://en.wikipedia.org/wiki/Logic_programming) paradigm and is **declarative** in nature (it's similar to [Datalog](https://en.wikipedia.org/wiki/Datalog)). This means that instead of directly encoding the computation graph, you just declare:

1. the inputs (and their numeric values, if any)
- i.e. the observed facts/data = objects, structures, knowledge graphs, relational databases, ...
- e.g. `atom(oxygen_1)`, `0.3 stable(oxygen)`, `8 protons(oxygen)`, `1.7 energy(oxygen,leve2)`, `[1.2,0,-1] features(oxygen)`, `[[0,2.1],[1.7,-1]] bond(oxygen_1,hydrogen_2)`
- e.g. `atom(oxygen_1)`, `0.3 stable(oxygen)`, `8 protons(oxygen)`, `1.7 energy(oxygen,leve2)`, `[1.2,0,-1] features(oxygen)`, `[[0,2.1],[1.7,-1]] bond(oxygen_1,hydrogen_2,covalent_1)`
1. the outputs (and their expected values - for supervised learning)
- i.e. the queries = classification labels, regression targets, ...
- e.g. `1 class`, `4.7 target(molecule_3)`, `0 relation(carbon,xenon,fluor)`
1. a set of rules applicable in your domain (and their learnable parameters)
1. a set of rules applicable in your domain (and their learnable parameters `W`)
- i.e. the generic knowledge/bias which you want to use. It does not have to be explicit.
- this is how you can encode diverse deep learning models, but also relational background knowledge and other constructs.
- e.g. `0.99: covalent(B) :- oxygen(X), hydrogen(Y), bond(X,Y,B).` or just `embed(X) :- W_1 embed(Y), bond(X,Y,_).`
- e.g. `0.99 covalent(B) :- oxygen(X), hydrogen(Y), bond(X,Y,B).` or just `embed(X) :- W_1 embed(Y), bond(X,Y,_).`

### Example
Consider a simple program for learning with molecular data<sup>[1](#myfootnote1)</sup>, encoding a generic idea that some hidden representation (predicate `h(.)`) of any chemical atom (variable `X`) is somewhat dependent on the other atoms (`a(Y)`) adjacent to it (`b(X,Y)`), with a parameterized rule as:
Expand Down Expand Up @@ -66,7 +67,7 @@ The framework is mostly optimized for quick, high-level prototyping of learning
- and generic [latent logic programs](https://link.springer.com/chapter/10.1007/978-3-319-78090-0_10)


<a name="myfootnote2">2</a>: _if you come from deep learning background, you may have heard terms such as "geometric deep learning" or "graph representation learning". Note also that this framework is not designed/limited to graphs only._
<a name="myfootnote2">2</a>: _if you come from deep learning background, you may be familiar with similar terms such as "geometric deep learning" or "graph representation learning". Note also that this framework is not designed/limited to graphs only._

### Getting started

Expand All @@ -81,7 +82,7 @@ The framework is mostly optimized for quick, high-level prototyping of learning
#### Running examples

1. download a [release](https://github.com/GustikS/NeuraLogic/releases) into some directory `DIR`
- or build from source with [Maven](https://maven.apache.org/) or [IntelliJ IDEA](https://www.jetbrains.com/idea/)
- or [build from source](https://github.com/GustikS/NeuraLogic/actions) with [Maven](https://maven.apache.org/) or [IntelliJ IDEA](https://www.jetbrains.com/idea/)
1. clone this repository (or just download the Resources/datasets directory) within `DIR`
- `git clone https://github.com/GustikS/NeuraLogic`
1. try some trivial examples from terminal in `DIR`
Expand Down Expand Up @@ -175,7 +176,7 @@ The project follows the standard [Maven structure](https://maven.apache.org/guid
- a more user friendly frontend
- plus integration to popular DL libraries
- Lambda calculus support in the language
- Structure learning module from the previous version
- Migrating structure learning module from the previous version

### Disclaimer
This is a second generation of the framework<sup>[3](#myfootnote2)</sup>, but it is still work in progress.
Expand Down
36 changes: 17 additions & 19 deletions Resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

<artifactId>Resources</artifactId>
<dependencies>
<dependency>
<groupId>cz.cvut.fel.ida</groupId>
<artifactId>Logic</artifactId>
<version>0.2.1-alpha</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>cz.cvut.fel.ida</groupId>
<artifactId>Logging</artifactId>
Expand All @@ -26,18 +33,19 @@
</dependency>

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>compile</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>org.junit.jupiter</groupId>-->
<!--<artifactId>junit-jupiter-api</artifactId>-->
<!--<version>5.6.1</version>-->
<!--<scope>compile</scope>-->
<!--</dependency>-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<version>5.6.1</version>
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -52,18 +60,8 @@
<version>1.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cz.cvut.fel.ida</groupId>
<artifactId>Logic</artifactId>
<version>0.2.1-alpha</version>
<scope>compile</scope>
</dependency>


</dependencies>

</project>
4 changes: 1 addition & 3 deletions Settings/src/main/java/cz/cvut/fel/ida/setup/Sources.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.cli.CommandLine;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.io.FileInputStream;
import java.io.Reader;
Expand Down Expand Up @@ -222,8 +221,7 @@ public static Sources setupFromCommandline(Settings settings, CommandLine cmd) {
if (settings.sourceFiles) {
sources = new SourceFiles(settings, cmd);
} else {
LOG.severe("Input streams other than from source files not implemented yet");
throw new NotImplementedException();
throw new UnsupportedOperationException("Input streams other than from source files not implemented yet");
}

if (cmd.hasOption("xval") || settings.crossvalidation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void export(Exportable iExportable) {
out.writeObject(iExportable);
out.flush();

} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.UnsupportedEncodingException;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.*;
Expand Down Expand Up @@ -58,10 +57,11 @@ public static String[] getDatasetArgs(String... args) {
}

public static String getResourcePath(String filename) {
URL resource = Thread.currentThread().getContextClassLoader().getResource(filename);
String path = resource.getPath();
// URL resource = Thread.currentThread().getContextClassLoader().getResource(filename);
// String path = resource.getPath();
String path = "../Resources/datasets/" + filename;
if (path.startsWith("/C:")) {
path = path.substring(1, path.length());
path = path.substring(1);
}
return path;
}
Expand Down
Loading

0 comments on commit 6475a60

Please sign in to comment.