diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..12b314f8 --- /dev/null +++ b/.github/workflows/maven.yml @@ -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 \ No newline at end of file diff --git a/Algebra/pom.xml b/Algebra/pom.xml index 8415a22d..978a140f 100644 --- a/Algebra/pom.xml +++ b/Algebra/pom.xml @@ -34,12 +34,12 @@ annotations 19.0.0 - - org.junit.jupiter - junit-jupiter-api - 5.6.1 - test - + + + + + + diff --git a/CLI/pom.xml b/CLI/pom.xml index 250c5080..722ea396 100644 --- a/CLI/pom.xml +++ b/CLI/pom.xml @@ -57,18 +57,12 @@ test - - org.openjdk.jmh - jmh-core - 1.23 - test - - - org.openjdk.jmh - jmh-generator-annprocess - 1.23 - test - + + + + + + diff --git a/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/cli/utils/ResourceFilesTest.java b/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/cli/utils/ResourceFilesTest.java index 6213825b..03176c62 100644 --- a/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/cli/utils/ResourceFilesTest.java +++ b/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/cli/utils/ResourceFilesTest.java @@ -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; @@ -28,6 +29,7 @@ void tearDown() { } @TestAnnotations.Fast + @Disabled void checkResourceFile() { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("relational").getFile()); @@ -35,12 +37,14 @@ void checkResourceFile() { } @TestAnnotations.Fast + @Disabled void getResource() { String tmp2 = Utilities.readResourceFile("dummy.txt"); LOG.fine(tmp2); } @TestAnnotations.Fast + @Disabled public void listAvailableResources() { boolean available = false; Enumeration e = null; diff --git a/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/revised/unsorted/UtilsTests.java b/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/revised/unsorted/UtilsTests.java index 9dfd20ad..98e9382b 100644 --- a/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/revised/unsorted/UtilsTests.java +++ b/CLI/src/test/java/cz/cvut/fel/ida/neuralogic/revised/unsorted/UtilsTests.java @@ -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; @@ -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()); diff --git a/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/NeuralogicLexer.java b/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/NeuralogicLexer.java index 7cfeab79..3c4965d7 100644 --- a/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/NeuralogicLexer.java +++ b/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/NeuralogicLexer.java @@ -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 { diff --git a/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4 b/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4 index 60126f9a..3f14e9c7 100644 --- a/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4 +++ b/Parsing/src/main/java/cz/cvut/fel/ida/logic/parsing/antlr/grammars/Neuralogic.g4 @@ -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; diff --git a/README.md b/README.md index 6efd00aa..eb6362c5 100644 --- a/README.md +++ b/README.md @@ -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[1](#myfootnote1), 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: @@ -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) -2: _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._ +2: _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 @@ -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` @@ -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[3](#myfootnote2), but it is still work in progress. diff --git a/Resources/pom.xml b/Resources/pom.xml index 4f0e27a4..11079599 100644 --- a/Resources/pom.xml +++ b/Resources/pom.xml @@ -11,6 +11,13 @@ Resources + + cz.cvut.fel.ida + Logic + 0.2.1-alpha + compile + + cz.cvut.fel.ida Logging @@ -26,18 +33,19 @@ - - org.junit.jupiter - junit-jupiter-api - 5.6.0 - compile - + + + + + + org.junit.jupiter junit-jupiter-params - 5.6.0 + 5.6.1 compile + org.hamcrest @@ -52,18 +60,8 @@ 1.23 compile - - org.openjdk.jmh - jmh-generator-annprocess - 1.23 - compile - - - cz.cvut.fel.ida - Logic - 0.2.1-alpha - compile - + + \ No newline at end of file diff --git a/Settings/src/main/java/cz/cvut/fel/ida/setup/Sources.java b/Settings/src/main/java/cz/cvut/fel/ida/setup/Sources.java index aaf2ad97..0dd6d2d5 100644 --- a/Settings/src/main/java/cz/cvut/fel/ida/setup/Sources.java +++ b/Settings/src/main/java/cz/cvut/fel/ida/setup/Sources.java @@ -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; @@ -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) { diff --git a/Utilities/src/main/java/cz/cvut/fel/ida/utils/exporting/JavaExporter.java b/Utilities/src/main/java/cz/cvut/fel/ida/utils/exporting/JavaExporter.java index d70e9639..52ade348 100644 --- a/Utilities/src/main/java/cz/cvut/fel/ida/utils/exporting/JavaExporter.java +++ b/Utilities/src/main/java/cz/cvut/fel/ida/utils/exporting/JavaExporter.java @@ -34,7 +34,7 @@ public void export(Exportable iExportable) { out.writeObject(iExportable); out.flush(); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } } diff --git a/Utilities/src/main/java/cz/cvut/fel/ida/utils/generic/Utilities.java b/Utilities/src/main/java/cz/cvut/fel/ida/utils/generic/Utilities.java index f22a5b24..ff44406c 100644 --- a/Utilities/src/main/java/cz/cvut/fel/ida/utils/generic/Utilities.java +++ b/Utilities/src/main/java/cz/cvut/fel/ida/utils/generic/Utilities.java @@ -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.*; @@ -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; } diff --git a/pom.xml b/pom.xml index 23c45c10..1583be43 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ pom 0.2.1-alpha + Resources Algebra Settings CLI @@ -27,7 +28,6 @@ Pipelines Utilities Workflow - Resources @@ -65,29 +65,39 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + Fast, Medium + Interactive, Slow, AdHoc, SlowBenchmark + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +