Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ffi and kotlin bindings #136

Merged
merged 2 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 81 additions & 67 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,73 +39,87 @@ Supported languages
Supported builtin entities
--------------------------

+---------------+---------------------+---------------------+---------------------+
| Entity | Identifier | Category | Supported languages |
+===============+=====================+=====================+=====================+
| AmountOfMoney | snips/amountOfMoney | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
| Time | snips/datetime | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
| Duration | snips/duration | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
| MusicAlbum | snips/musicAlbum | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+---------------------+
| MusicArtist | snips/musicArtist | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+---------------------+
| MusicTrack | snips/musicTrack | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+---------------------+
| Number | snips/number | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
| Ordinal | snips/ordinal | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
| Percentage | snips/percentage | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
+---------------+---------------------+---------------------+---------------------+
| Temperature | snips/temperature | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
+---------------+---------------------+---------------------+---------------------+
+---------------+---------------------+---------------------+-----------------------+
| Entity | Identifier | Category | Supported languages |
+===============+=====================+=====================+=======================+
| AmountOfMoney | snips/amountOfMoney | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| Time | snips/datetime | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| Duration | snips/duration | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| MusicAlbum | snips/musicAlbum | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+-----------------------+
| MusicArtist | snips/musicArtist | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+-----------------------+
| MusicTrack | snips/musicTrack | `Gazetteer Entity`_ | | English |
| | | | | French |
+---------------+---------------------+---------------------+-----------------------+
| Number | snips/number | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| Ordinal | snips/ordinal | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| Percentage | snips/percentage | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+
| Temperature | snips/temperature | `Grammar Entity`_ | | German |
| | | | | English |
| | | | | Spanish |
| | | | | French |
| | | | | Italian |
| | | | | Japanese |
| | | | | Korean |
| | | | | Portuguese - Brazil |
| | | | | Portuguese - Europe |
+---------------+---------------------+---------------------+-----------------------+

Grammar Entity
--------------
Expand Down
36 changes: 36 additions & 0 deletions ffi/ffi-macros/src/ontology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ impl Drop for CIntentClassifierResult {
}
}

/// Wrapper around a list of IntentClassifierResult
#[repr(C)]
#[derive(Debug)]
pub struct CIntentClassifierResultList {
/// Pointer to the first result of the list
pub intent_classifier_results: *const CIntentClassifierResult,
/// Number of results in the list
pub size: libc::int32_t,
}

impl From<Vec<IntentClassifierResult>> for CIntentClassifierResultList {
fn from(input: Vec<IntentClassifierResult>) -> Self {
Self {
size: input.len() as libc::int32_t,
intent_classifier_results: Box::into_raw(
input
.into_iter()
.map(CIntentClassifierResult::from)
.collect::<Vec<_>>()
.into_boxed_slice(),
) as *const CIntentClassifierResult,
}
}
}

impl Drop for CIntentClassifierResultList {
fn drop(&mut self) {
let _ = unsafe {
Box::from_raw(slice::from_raw_parts_mut(
self.intent_classifier_results as *mut CIntentClassifierResult,
self.size as usize,
))
};
}
}

/// Wrapper around a slot list
#[repr(C)]
#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
extern crate ffi_utils;
extern crate snips_nlu_ontology_ffi_macros;

use ffi_utils::{generate_error_handling, wrap};
use snips_nlu_ontology_ffi_macros::export_nlu_ontology_c_symbols;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ fun Float?.readFloat(): Float? = if (this!! < 0) null else this!!
fun CSlotValue?.readSlotValue(): SlotValue = this!!.toSlotValue()

class CIntentParserResult(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var input: Pointer? = null
@JvmField var intent: CIntentClassifierResult? = null
@JvmField var slots: CSlots? = null

init {
read()
}

override fun getFieldOrder() = listOf("input",
"intent",
"slots")
Expand All @@ -53,20 +54,55 @@ class CIntentParserResult(p: Pointer) : Structure(p), Structure.ByReference {

}

class CIntentClassifierResult : Structure(), Structure.ByReference {
class CIntentClassifierResult(p: Pointer?) : Structure(p), Structure.ByReference {

@JvmField var intent_name: Pointer? = null
@JvmField var confidence_score: Float? = null

init {
read()
}

constructor(): this(null)

override fun getFieldOrder() = listOf("intent_name", "confidence_score")

fun toIntentClassifierResult() = IntentClassifierResult(intentName = intent_name?.readString(),
confidenceScore = confidence_score!!)
}

class CSlots : Structure(), Structure.ByReference {
class CIntentClassifierResultList(p: Pointer?) : Structure(p), Structure.ByReference {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name it CIntentClassifierResults to follow the exisiting convention ? (we use s in nlu ontology and Array in hermes... let's not introduce a new one)


@JvmField var intent_classifier_results: Pointer? = null
@JvmField var size: Int = -1

init {
read()
}

constructor(): this(null)

override fun getFieldOrder() = listOf("intent_classifier_results", "size")

fun toIntentClassifierResultList(): List<IntentClassifierResult> =
if (size > 0)
CIntentClassifierResult(intent_classifier_results!!)
.toArray(size)
.map { (it as CIntentClassifierResult).toIntentClassifierResult() }
else listOf<IntentClassifierResult>()
}

class CSlots(p: Pointer?) : Structure(p), Structure.ByReference {

@JvmField var slots: Pointer? = null
@JvmField var size: Int = -1

init {
read()
}

constructor(): this(null)

override fun getFieldOrder() = listOf("slots", "size")

fun toSlotList(): List<Slot> =
Expand Down Expand Up @@ -149,14 +185,17 @@ class CSlotValue : Structure(), Structure.ByValue {
}

class CInstantTimeValue(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var value: Pointer? = null
@JvmField var grain: Int? = null
@JvmField var precision: Int? = null

init {
read()
}

override fun getFieldOrder() = listOf("value", "grain", "precision")

fun toInstantTimeValue(): InstantTimeValue {
return InstantTimeValue(value = value.readString(),
grain = grain.readGrain(),
Expand All @@ -166,25 +205,29 @@ class CInstantTimeValue(p: Pointer) : Structure(p), Structure.ByReference {
}

class CTimeIntervalValue(p: Pointer) : Structure(p), Structure.ByReference {

@JvmField var from: Pointer? = null
@JvmField var to: Pointer? = null

init {
read()
}

@JvmField var from: Pointer? = null
@JvmField var to: Pointer? = null
override fun getFieldOrder() = listOf("from", "to")

fun toTimeIntervalValue() = TimeIntervalValue(from = from?.readString(), to = to?.readString())
}

class CAmountOfMoneyValue(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var value: Float? = null
@JvmField var precision: Int? = null
@JvmField var unit: Pointer? = null

init {
read()
}

override fun getFieldOrder() = listOf("unit", "value", "precision")

fun toAmountOfMoneyValue() = AmountOfMoneyValue(value = value!!,
Expand All @@ -193,13 +236,14 @@ class CAmountOfMoneyValue(p: Pointer) : Structure(p), Structure.ByReference {
}

class CTemperatureValue(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var value: Float? = null
@JvmField var unit: Pointer? = null

init {
read()
}

override fun getFieldOrder() = listOf("unit", "value")

fun toTemperatureValue() = TemperatureValue(value = value!!,
Expand All @@ -208,9 +252,6 @@ class CTemperatureValue(p: Pointer) : Structure(p), Structure.ByReference {
}

class CDurationValue(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var years: Long? = null
@JvmField var quarters: Long? = null
Expand All @@ -222,6 +263,10 @@ class CDurationValue(p: Pointer) : Structure(p), Structure.ByReference {
@JvmField var seconds: Long? = null
@JvmField var precision: Int? = null

init {
read()
}

override fun getFieldOrder() = listOf("years",
"quarters",
"months",
Expand All @@ -245,9 +290,6 @@ class CDurationValue(p: Pointer) : Structure(p), Structure.ByReference {


class CSlot(p: Pointer) : Structure(p), Structure.ByReference {
init {
read()
}

@JvmField var raw_value: Pointer? = null
@JvmField var value: CSlotValue? = null
Expand All @@ -257,6 +299,10 @@ class CSlot(p: Pointer) : Structure(p), Structure.ByReference {
@JvmField var slot_name: Pointer? = null
@JvmField var confidence_score: Float? = null

init {
read()
}

override fun getFieldOrder() = listOf("value",
"raw_value",
"entity",
Expand Down
Loading