Skip to content

Commit

Permalink
Merge pull request #9 from snipsco/release/0.53.1
Browse files Browse the repository at this point in the history
Release 0.53.1
  • Loading branch information
Adrien Ball authored Feb 26, 2018
2 parents 57076dc + 8ea4477 commit 90fb44e
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 53 deletions.
1 change: 1 addition & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-ontology"
version = "0.53.0"
version = "0.53.1"
authors = [
"Adrien Ball <[email protected]>",
"Thibaut Lorrain <[email protected]>",
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion snips-nlu-ontology-doc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-ontology-doc"
version = "0.53.0"
version = "0.53.1"
authors = ["Adrien Ball <[email protected]>"]

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion snips-nlu-ontology-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-ontology-ffi"
version = "0.53.0"
version = "0.53.1"
authors = [
"Kevin Lefevre <[email protected]>",
"Thibaut Lorrain <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@ buildscript {
}
}

version = "0.53.0"
version = "0.53.1"
group = "ai.snips"


apply plugin: 'kotlin'

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

repositories {
jcenter()
}

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'
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Slot>)
@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<Slot>)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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-<TARGET>
args = (["cargo", "build"] + list(self.extra_cargo_args or []))
if not self.debug:
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "snips-nlu-ontology-rs"
version = "0.53.1"
authors = ["Adrien Ball <[email protected]>"]

[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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate snips_nlu_ontology_ffi;

pub use snips_nlu_ontology_ffi::*;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.53.0
0.53.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions update_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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__

0 comments on commit 90fb44e

Please sign in to comment.