diff --git a/.travis/install.sh b/.travis/install.sh index 6818ff4..b0743ae 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -5,4 +5,5 @@ echo "Rust build" export PATH="/usr/local/bin:$HOME/.cargo/bin:$PATH" +perl -p -i -e "s/^snips-nlu-ontology-ffi = .*\$/snips-nlu-ontology-ffi = { path = \"..\/..\/..\" \}/g" */**/**/*/Cargo.toml cargo build --all || die "Rust build failed" diff --git a/Cargo.toml b/Cargo.toml index 9ae5d24..feb7bac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snips-nlu-ontology" -version = "0.53.0" +version = "0.53.1" authors = [ "Adrien Ball ", "Thibaut Lorrain ", @@ -12,7 +12,8 @@ description = "Ontology of the Rust NLU library API" [workspace] members = [ "snips-nlu-ontology-ffi", - "snips-nlu-ontology-doc" + "snips-nlu-ontology-doc", + "snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs" ] [dependencies] diff --git a/snips-nlu-ontology-doc/Cargo.toml b/snips-nlu-ontology-doc/Cargo.toml index e32a5c1..8c7069e 100644 --- a/snips-nlu-ontology-doc/Cargo.toml +++ b/snips-nlu-ontology-doc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snips-nlu-ontology-doc" -version = "0.53.0" +version = "0.53.1" authors = ["Adrien Ball "] [build-dependencies] diff --git a/snips-nlu-ontology-ffi/Cargo.toml b/snips-nlu-ontology-ffi/Cargo.toml index 6c1e913..f8e65d1 100644 --- a/snips-nlu-ontology-ffi/Cargo.toml +++ b/snips-nlu-ontology-ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snips-nlu-ontology-ffi" -version = "0.53.0" +version = "0.53.1" authors = [ "Kevin Lefevre ", "Thibaut Lorrain ", diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/build.gradle b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/build.gradle index 3b0870d..79ddeb5 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/build.gradle +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/build.gradle @@ -8,12 +8,15 @@ buildscript { } } -version = "0.53.0" +version = "0.53.1" group = "ai.snips" apply plugin: 'kotlin' +sourceCompatibility = "1.7" +targetCompatibility = "1.7" + repositories { jcenter() } @@ -21,6 +24,16 @@ repositories { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" compile 'net.java.dev.jna:jna:4.5.0' + compile 'org.parceler:parceler-api:1.1.9' +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives sourcesJar } apply plugin: 'maven' @@ -37,9 +50,13 @@ uploadArchives { snapshotRepository(url: "https://nexus-repository.snips.ai/repository/snips-maven-snapshots/") { authentication(userName: _nexusUsername, password: _nexusPassword) } - pom.whenConfigured { pom -> - pom.dependencies.find { dep -> dep.groupId == 'net.java.dev.jna' && dep.artifactId == 'jna' }.scope = "provided" - } } } } + +def installer = install.repositories.mavenInstaller +def deployer = uploadArchives.repositories.mavenDeployer + +[installer, deployer]*.pom*.whenConfigured { pom -> + pom.dependencies.find { dep -> dep.groupId == 'net.java.dev.jna' && dep.artifactId == 'jna' }.scope = "provided" +} diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/gradle/wrapper/gradle-wrapper.properties b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/gradle/wrapper/gradle-wrapper.properties index f16d266..cafccaf 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Jan 31 17:48:14 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/src/main/kotlin/ai/snips/nlu/ontology/Ontology.kt b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/src/main/kotlin/ai/snips/nlu/ontology/Ontology.kt index 25af56b..f302e12 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/src/main/kotlin/ai/snips/nlu/ontology/Ontology.kt +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-kotlin/src/main/kotlin/ai/snips/nlu/ontology/Ontology.kt @@ -9,17 +9,30 @@ import ai.snips.nlu.ontology.SlotValue.Type.ORDINAL import ai.snips.nlu.ontology.SlotValue.Type.TEMPERATURE import ai.snips.nlu.ontology.SlotValue.Type.TIME_INTERVAL import ai.snips.nlu.ontology.SlotValue.Type.PERCENTAGE +import org.parceler.Parcel +import org.parceler.Parcel.Serialization.BEAN +import org.parceler.ParcelConstructor +import org.parceler.ParcelProperty -data class Range(val start: Int, val end: Int) +@Parcel(BEAN) +data class Range @ParcelConstructor constructor(@ParcelProperty("start") val start: Int, + @ParcelProperty("end") val end: Int) -data class Slot(val rawValue: String, val value: SlotValue, val range: Range?, val entity: String, val slotName: String) +@Parcel(BEAN) +data class Slot @ParcelConstructor constructor(@ParcelProperty("rawValue") val rawValue: String, + @ParcelProperty("value") val value: SlotValue, + @ParcelProperty("range") val range: Range?, + @ParcelProperty("entity") val entity: String, + @ParcelProperty("slotName") val slotName: String) + +enum class Precision { APPROXIMATE, EXACT } -enum class Precision {APPROXIMATE, EXACT } enum class Grain { YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND } // TODO : add converters to JSR310 / ThreeTen types -sealed class SlotValue(val type: SlotValue.Type) { +sealed class SlotValue(val type: Type) { + @Parcel enum class Type { CUSTOM, NUMBER, @@ -32,25 +45,61 @@ sealed class SlotValue(val type: SlotValue.Type) { PERCENTAGE, } - data class CustomValue(val value: String) : SlotValue(CUSTOM) - data class NumberValue(val value: Double) : SlotValue(NUMBER) - data class PercentageValue(val value: Double) : SlotValue(PERCENTAGE) - data class OrdinalValue(val value: Long) : SlotValue(ORDINAL) - data class InstantTimeValue(val value: String, val grain: Grain, val precision: Precision) : SlotValue(INSTANT_TIME) - data class TimeIntervalValue(val from: String, val to: String) : SlotValue(TIME_INTERVAL) - data class AmountOfMoneyValue(val value: Float, val precision: Precision, val unit: String) : SlotValue(AMOUNT_OF_MONEY) - data class TemperatureValue(val value: Float, val unit: String) : SlotValue(TEMPERATURE) - data class DurationValue(val years: Long, - val quarters: Long, - val months: Long, - val weeks: Long, - val days: Long, - val hours: Long, - val minutes: Long, - val seconds: Long, - val precision: Precision) : SlotValue(DURATION) + @Parcel(BEAN) + data class CustomValue @ParcelConstructor constructor(@ParcelProperty("value") val value: String) : SlotValue(CUSTOM) + + @Parcel(BEAN) + data class NumberValue @ParcelConstructor constructor(@ParcelProperty("value") val value: Double) : SlotValue(NUMBER) + + @Parcel(BEAN) + data class PercentageValue @ParcelConstructor constructor(@ParcelProperty("value") val value: Double) : SlotValue(PERCENTAGE) + + @Parcel(BEAN) + data class OrdinalValue @ParcelConstructor constructor(@ParcelProperty("value") val value: Long) : SlotValue(ORDINAL) + + @Parcel(BEAN) + data class InstantTimeValue @ParcelConstructor constructor( + @ParcelProperty("value") val value: String, + @ParcelProperty("grain") val grain: Grain, + @ParcelProperty("precision") val precision: Precision) : SlotValue(INSTANT_TIME) + + @Parcel(BEAN) + data class TimeIntervalValue @ParcelConstructor constructor( + @ParcelProperty("from") val from: String, + @ParcelProperty("to") val to: String) : SlotValue(TIME_INTERVAL) + + @Parcel(BEAN) + data class AmountOfMoneyValue @ParcelConstructor constructor( + @ParcelProperty("value") val value: Float, + @ParcelProperty("precision") val precision: Precision, + @ParcelProperty("unit") val unit: String) : SlotValue(AMOUNT_OF_MONEY) + + @Parcel(BEAN) + data class TemperatureValue @ParcelConstructor constructor( + @ParcelProperty("value") val value: Float, + @ParcelProperty("unit") val unit: String) : SlotValue(TEMPERATURE) + + @Parcel(BEAN) + data class DurationValue @ParcelConstructor constructor( + @ParcelProperty("years") val years: Long, + @ParcelProperty("quarters") val quarters: Long, + @ParcelProperty("months") val months: Long, + @ParcelProperty("weeks") val weeks: Long, + @ParcelProperty("days") val days: Long, + @ParcelProperty("hours") val hours: Long, + @ParcelProperty("minutes") val minutes: Long, + @ParcelProperty("seconds") val seconds: Long, + @ParcelProperty("precision") val precision: Precision) : SlotValue(DURATION) } -data class IntentClassifierResult(val intentName: String, val probability: Float) -data class IntentParserResult(val input: String, val intent: IntentClassifierResult?, val slots: List) +@Parcel(BEAN) +data class IntentClassifierResult @ParcelConstructor constructor( + @ParcelProperty("intentName") val intentName: String, + @ParcelProperty("probability") val probability: Float) + +@Parcel(BEAN) +data class IntentParserResult @ParcelConstructor constructor( + @ParcelProperty("input") val input: String, + @ParcelProperty("intent") val intent: IntentClassifierResult?, + @ParcelProperty("slots") val slots: List) diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/README.rst b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/README.rst index f2e65a5..9885112 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/README.rst +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/README.rst @@ -4,15 +4,25 @@ Snips NLU Ontology Installation ------------ -To manage dependencies properly, it is recommended to work in a virtual environment: +This package can be installed via pip from a source distribution. As it contains +some ``rust`` code ``rust`` must be installed on your machine. + +To install Rust, run the following in your terminal, then follow the onscreen instructions: + +.. code-block:: console + + curl https://sh.rustup.rs -sSf | sh + + +You will also need the python lib ``setuptools_rust``: .. code-block:: console - virtualenv venv - . venv/bin/activate + pip install setuptools_rust -This package can be installed via pip with the following command: +Finally, you can install ``snips-nlu-ontology`` using pip: -.. code-block:: python +.. code-block:: console pip install snips-nlu-ontology + diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/rust_build.py b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/rust_build.py index 9129173..7c814fe 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/rust_build.py +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/rust_build.py @@ -13,8 +13,9 @@ from distutils.cmd import Command from distutils.command.install_lib import install_lib -CARGO_ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) -GLOBAL_ROOT_PATH = os.path.dirname(CARGO_ROOT_PATH) +RUST_CRATE_NAME = "snips-nlu-ontology-rs" +ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) +CARGO_ROOT_PATH = os.path.join(ROOT_PATH, RUST_CRATE_NAME) class RustBuildCommand(Command): @@ -40,7 +41,9 @@ def finalize_options(self): def run(self): # Execute cargo. try: - target_tuple = os.environ.get('CARGO_TARGET') + target_tuple = os.environ.get("CARGO_TARGET") + os.environ["CARGO_TARGET_DIR"] = os.path.join(CARGO_ROOT_PATH, + "target") # TODO Switch to make build- args = (["cargo", "build"] + list(self.extra_cargo_args or [])) if not self.debug: @@ -69,27 +72,27 @@ def run(self): suffix = "release" if target_tuple: - target_dir = os.path.join(GLOBAL_ROOT_PATH, "target", target_tuple, - suffix) + target_dir = os.path.join(CARGO_ROOT_PATH, "target", target_tuple, + suffix, "deps") else: - target_dir = os.path.join(GLOBAL_ROOT_PATH, "target", suffix) + target_dir = os.path.join(CARGO_ROOT_PATH, "target", suffix, + "deps") if sys.platform == "win32": - wildcard_so = "*snips_nlu_ontology*.dll" + wildcard_so = "*snips_nlu_ontology_ffi*.dll" elif sys.platform == "darwin": - wildcard_so = "*snips_nlu_ontology*.dylib" + wildcard_so = "*snips_nlu_ontology_ffi*.dylib" else: - wildcard_so = "*snips_nlu_ontology*.so" + wildcard_so = "*snips_nlu_ontology_ffi*.so" try: dylib_path = glob.glob(os.path.join(target_dir, wildcard_so))[0] except IndexError: - raise Exception( - "rust build failed; unable to find any .dylib in %s" % - target_dir) + raise Exception("rust build failed; unable to find any .dylib in " + "%s" % target_dir) package_name = self.distribution.metadata.name - root_path = os.path.dirname(os.path.abspath(__file__)) - dylib_resource_path = os.path.join(root_path, package_name, "dylib", + + dylib_resource_path = os.path.join(ROOT_PATH, package_name, "dylib", os.path.basename(dylib_path)) print("from: ", dylib_path) print("to: ", dylib_resource_path) diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/.gitignore b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/.gitignore new file mode 100644 index 0000000..e5be03f --- /dev/null +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/.gitignore @@ -0,0 +1,13 @@ +# Created by .ignore support plugin (hsz.mobi) +### Rust template +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/Cargo.toml b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/Cargo.toml new file mode 100644 index 0000000..494d67c --- /dev/null +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "snips-nlu-ontology-rs" +version = "0.53.1" +authors = ["Adrien Ball "] + +[lib] +name = "snips_nlu_ontology_rs" +crate-type = ["cdylib"] + +[dependencies] +snips-nlu-ontology-ffi = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.53.1" } diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/src/lib.rs b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/src/lib.rs new file mode 100644 index 0000000..dbb432e --- /dev/null +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/src/lib.rs @@ -0,0 +1,3 @@ +extern crate snips_nlu_ontology_ffi; + +pub use snips_nlu_ontology_ffi::*; diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/__version__ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/__version__ index 7f422a1..3f99a6d 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/__version__ +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/__version__ @@ -1 +1 @@ -0.53.0 +0.53.1 diff --git a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/utils.py b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/utils.py index 2b43600..beabc48 100644 --- a/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/utils.py +++ b/snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/utils.py @@ -5,7 +5,7 @@ from glob import glob dylib_dir = os.path.join(os.path.dirname(__file__), "dylib") -dylib_path = glob(os.path.join(dylib_dir, "libsnips_nlu_ontology*"))[0] +dylib_path = glob(os.path.join(dylib_dir, "libsnips_nlu_ontology_ffi*"))[0] lib = cdll.LoadLibrary(dylib_path) diff --git a/update_version.sh b/update_version.sh index 9cd5ccf..c07caaf 100755 --- a/update_version.sh +++ b/update_version.sh @@ -8,5 +8,7 @@ parseRustVersion() { NEW_VERSION=$(parseRustVersion) echo "Updating versions to version ${NEW_VERSION}" perl -p -i -e "s/^version = \".*\"\$/version = \"$NEW_VERSION\"/g" */Cargo.toml +perl -p -i -e "s/^version = \".*\"\$/version = \"$NEW_VERSION\"/g" */**/**/*/Cargo.toml +perl -p -i -e "s/https:\/\/github\.com\/snipsco\/snips-nlu-ontology\", tag = \".*\"/https:\/\/github\.com\/snipsco\/snips-nlu-ontology\", tag = \"$NEW_VERSION\"/g" snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips-nlu-ontology-rs/Cargo.toml perl -p -i -e "s/^version = \".*\"\$/version = \"$NEW_VERSION\"/g" */**/*/build.gradle echo "$NEW_VERSION" > snips-nlu-ontology-ffi/platforms/snips-nlu-ontology-python/snips_nlu_ontology/__version__