Skip to content

Commit

Permalink
[natural-language] rename namespace mlKitLanguage -> naturalLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar committed Aug 2, 2019
1 parent 02aa55a commit 2fddf9e
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 153 deletions.
34 changes: 2 additions & 32 deletions CHANGELOG.md
Expand Up @@ -361,41 +361,11 @@ The Remote Config API has had a significant API change as originally highlighted

---

## ML Kit Natural Language (mlKitLanguage) - **[NEW]**
## ML Kit Natural Language (naturalLanguage) - **[NEW]**

- [NEW] Implemented support for language identification APIs

**Identify a single language:**

```js
const language = await firebase.mlKitLanguage().identifyLanguage('Hello there. General Kenobi.');
console.warn(language); // en

const unknownLanguage = await firebase
.mlKitLanguage()
.identifyLanguage('foo bar baz', { confidenceThreshold: 0.9 });
console.warn(language); // und
```

**Identify a multiple languages:**

```js
const identifiedLanguages = firebase.mlKitLanguage().identifyPossibleLanguages('hello world');
console.warn(identifiedLanguages[0].language); // en
```

- [NEW] Implemented support for [Smart Replies](https://firebase.google.com/docs/ml-kit/generate-smart-replies)
- [Example Video](https://twitter.com/mikediarmid/status/1128837402481635331)

```js
const conversation = firebase.mlKitLanguage().newSmartReplyConversation();
conversation.addRemoteUserMessage('Hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');
conversation.addLocalUserMessage('That sounds great!');
conversation.addRemoteUserMessage('Great, does 12pm work for you?', Date.now(), 'jimBobTheGreat');

const suggestedReplies = await conversation.getSuggestedReplies();
console.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]
```
- [Example Video](https://twitter.com/mikediarmid/status/1128837402481635331)

> ML Kit Translate APIs to come in a later release.
Expand Down
2 changes: 1 addition & 1 deletion docs/ml-natural-language/quick-start.md
Expand Up @@ -20,7 +20,7 @@ yarn add @react-native-firebase/ml-natural-language
Import the ML Kit package into your project:

```js
import mlNaturalLanguage from '@react-native-firebase/ml-natural-language';
import naturalLanguage from '@react-native-firebase/ml-natural-language';
```

The package also provides access to the firebase instance:
Expand Down
32 changes: 16 additions & 16 deletions docs/typedoc.json
Expand Up @@ -554,14 +554,14 @@
},
{
"id": 1544,
"name": "mlKitLanguage",
"name": "naturalLanguage",
"kind": 2048,
"kindString": "Method",
"flags": {},
"signatures": [
{
"id": 1545,
"name": "mlKitLanguage",
"name": "naturalLanguage",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
Expand All @@ -576,7 +576,7 @@
{
"fileName": "ml-natural-language/lib/index.d.ts",
"line": 281,
"character": 19
"character": 21
}
]
},
Expand Down Expand Up @@ -1248,15 +1248,15 @@
},
{
"id": 1543,
"name": "mlKitLanguage",
"name": "naturalLanguage",
"kind": 1024,
"kindString": "Property",
"flags": {},
"sources": [
{
"fileName": "ml-natural-language/lib/index.d.ts",
"line": 277,
"character": 19
"character": 21
}
],
"type": {
Expand Down Expand Up @@ -31338,7 +31338,7 @@
},
"comment": {
"shortText": "Firebase ML Kit package for React Native.",
"text": "#### Example 1\n\nAccess the firebase export from the `mlKitLanguage` package:\n\n```js\nimport { firebase } from '@react-native-firebase/ml-natural-language';\n\n// firebase.mlKitLanguage().X\n```\n\n#### Example 2\n\nUsing the default export from the `mlKitLanguage` package:\n\n```js\nimport mlKitLanguage from '@react-native-firebase/ml-natural-language';\n\n// mlKitLanguage().X\n```\n\n#### Example 3\n\nUsing the default export from the `app` package:\n\n```js\nimport firebase from '@react-native-firebase/app';\nimport '@react-native-firebase/ml-natural-language';\n\n// firebase.mlKitLanguage().X\n```\n",
"text": "#### Example 1\n\nAccess the firebase export from the `naturalLanguage` package:\n\n```js\nimport { firebase } from '@react-native-firebase/ml-natural-language';\n\n// firebase.naturalLanguage().X\n```\n\n#### Example 2\n\nUsing the default export from the `naturalLanguage` package:\n\n```js\nimport naturalLanguage from '@react-native-firebase/ml-natural-language';\n\n// naturalLanguage().X\n```\n\n#### Example 3\n\nUsing the default export from the `app` package:\n\n```js\nimport firebase from '@react-native-firebase/app';\nimport '@react-native-firebase/ml-natural-language';\n\n// firebase.naturalLanguage().X\n```\n",
"tags": [
{
"tag": "firebase",
Expand All @@ -31357,7 +31357,7 @@
},
"comment": {
"shortText": "The Firebase ML Kit service interface.",
"text": "> This module is available for the default app only.\n\n#### Example\n\nGet the ML Kit service for the default app:\n\n```js\nconst defaultAppMLKit = firebase.mlKitLanguage();\n```\n"
"text": "> This module is available for the default app only.\n\n#### Example\n\nGet the ML Kit service for the default app:\n\n```js\nconst defaultAppMLKit = firebase.naturalLanguage();\n```\n"
},
"children": [
{
Expand Down Expand Up @@ -31405,7 +31405,7 @@
"flags": {},
"comment": {
"shortText": "Identifies the main language for the given text.",
"text": "Returns a promise that resolves with a [BCP-47 language code](https://en.wikipedia.org/wiki/IETF_language_tag) of the detected language.\n\nIf the language was undetected or unknown the code returned is `und`.\n\n#### Example\n\n```js\nconst language = await firebase.mlKitLanguage().identifyLanguage('Hello there. General Kenobi.');\nconsole.warn(language); // en\n\nconst unknownLanguage = await firebase.mlKitLanguage().identifyLanguage('foo bar baz', { confidenceThreshold: 0.9 });\nconsole.warn(language); // und\n```\n"
"text": "Returns a promise that resolves with a [BCP-47 language code](https://en.wikipedia.org/wiki/IETF_language_tag) of the detected language.\n\nIf the language was undetected or unknown the code returned is `und`.\n\n#### Example\n\n```js\nconst language = await firebase.naturalLanguage().identifyLanguage('Hello there. General Kenobi.');\nconsole.warn(language); // en\n\nconst unknownLanguage = await firebase.naturalLanguage().identifyLanguage('foo bar baz', { confidenceThreshold: 0.9 });\nconsole.warn(language); // und\n```\n"
},
"parameters": [
{
Expand Down Expand Up @@ -31477,7 +31477,7 @@
"flags": {},
"comment": {
"shortText": "Identifies possible languages for the given text.",
"text": "#### Example\n\n```js\nconst identifiedLanguages = firebase.mlKitLanguage().identifyPossibleLanguages('hello world');\nconsole.warn(identifiedLanguages[0].language); // en\n```\n"
"text": "#### Example\n\n```js\nconst identifiedLanguages = firebase.naturalLanguage().identifyPossibleLanguages('hello world');\nconsole.warn(identifiedLanguages[0].language); // en\n```\n"
},
"parameters": [
{
Expand Down Expand Up @@ -31553,7 +31553,7 @@
"flags": {},
"comment": {
"shortText": "Returns a new instance of SmartReplyConversation.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\n```\n"
},
"parameters": [
{
Expand Down Expand Up @@ -31641,7 +31641,7 @@
},
"comment": {
"shortText": "A class representing a Smart Reply conversation in your app.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\n```\n\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\n```\n\n"
},
"children": [
{
Expand All @@ -31661,7 +31661,7 @@
"flags": {},
"comment": {
"shortText": "Add a local message to this conversation, e.g. for the currently signed in user on this device.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('Hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\nconversation.addLocalUserMessage('That sounds great!');\nconversation.addRemoteUserMessage('Great, does 12pm work for you?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('Hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\nconversation.addLocalUserMessage('That sounds great!');\nconversation.addRemoteUserMessage('Great, does 12pm work for you?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
},
"parameters": [
{
Expand Down Expand Up @@ -31735,7 +31735,7 @@
"flags": {},
"comment": {
"shortText": "Add a remote message to this conversation, e.g. for a user that's not on this device.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
},
"parameters": [
{
Expand Down Expand Up @@ -31812,7 +31812,7 @@
"flags": {},
"comment": {
"shortText": "Removes all messages from this conversation, e.g. all messages added via `addLocalUserMessage` and `addRemoteUserMessage`.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n// start over\nconversation.clearMessages();\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n// start over\nconversation.clearMessages();\n```\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -31845,7 +31845,7 @@
"flags": {},
"comment": {
"shortText": "Get suggested replies for the current conversation.",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
},
"type": {
"type": "reference",
Expand Down Expand Up @@ -32059,7 +32059,7 @@
},
"comment": {
"shortText": "An interface representing a suggest reply, an array of these are returned from `SmartReplyConversation.getSuggestedReplies`",
"text": "#### Example\n\n```js\nconst conversation = firebase.mlKitLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
"text": "#### Example\n\n```js\nconst conversation = firebase.naturalLanguage().newSmartReplyConversation();\nconversation.addRemoteUserMessage('hey, want to get lunch today?', Date.now(), 'jimBobTheGreat');\n\nconst suggestedReplies = await conversation.getSuggestedReplies();\nconsole.log(suggestedReplies); // [ { text: 'Sure' }, ...etc ]\n```\n"
},
"children": [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/typedoc.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/app/lib/internal/constants.js
Expand Up @@ -36,7 +36,7 @@ export const KNOWN_NAMESPACES = [
'storage',
'dynamicLinks',
'messaging',
'mlKitLanguage',
'naturalLanguage',
'vision',
'notifications',
'perf',
Expand Down
26 changes: 13 additions & 13 deletions packages/ml-natural-language/e2e/languageId.e2e.js
Expand Up @@ -15,20 +15,20 @@
*
*/

describe('mlKitLanguage() -> Language ID', () => {
describe('naturalLanguage() -> Language ID', () => {
describe('identifyLanguage()', () => {
it('returns a string of the identified language', async () => {
const languageDe = await firebase.mlKitLanguage().identifyLanguage('Hallo welt');
const languageEn = await firebase.mlKitLanguage().identifyLanguage('Hello world');
const languageFr = await firebase.mlKitLanguage().identifyLanguage('Bonjour le monde');
const languageDe = await firebase.naturalLanguage().identifyLanguage('Hallo welt');
const languageEn = await firebase.naturalLanguage().identifyLanguage('Hello world');
const languageFr = await firebase.naturalLanguage().identifyLanguage('Bonjour le monde');
should.equal(languageDe, 'de');
should.equal(languageEn, 'en');
should.equal(languageFr, 'fr');
});

it('accepts a `confidenceThreshold` option', async () => {
const languageDeDefault = await firebase.mlKitLanguage().identifyLanguage('Hallo');
const languageDeLowConfidence = await firebase.mlKitLanguage().identifyLanguage('Hallo', {
const languageDeDefault = await firebase.naturalLanguage().identifyLanguage('Hallo');
const languageDeLowConfidence = await firebase.naturalLanguage().identifyLanguage('Hallo', {
confidenceThreshold: 0.2,
});
should.equal(languageDeDefault, 'und');
Expand All @@ -37,7 +37,7 @@ describe('mlKitLanguage() -> Language ID', () => {

it('throws an error if text is not a string', async () => {
try {
firebase.mlKitLanguage().identifyLanguage(false);
firebase.naturalLanguage().identifyLanguage(false);
return Promise.reject(new Error('Did not throw'));
} catch (e) {
e.message.should.containEql('must be a string value');
Expand All @@ -47,7 +47,7 @@ describe('mlKitLanguage() -> Language ID', () => {

it('throws an error if options is not an object', async () => {
try {
firebase.mlKitLanguage().identifyLanguage('hello', false);
firebase.naturalLanguage().identifyLanguage('hello', false);
return Promise.reject(new Error('Did not throw'));
} catch (e) {
e.message.should.containEql('must be an object');
Expand All @@ -57,7 +57,7 @@ describe('mlKitLanguage() -> Language ID', () => {

it('throws an error if options.confidenceThreshold is not a float value', async () => {
try {
firebase.mlKitLanguage().identifyLanguage('hello', { confidenceThreshold: 'boop' });
firebase.naturalLanguage().identifyLanguage('hello', { confidenceThreshold: 'boop' });
return Promise.reject(new Error('Did not throw'));
} catch (e) {
e.message.should.containEql('must be a float value between 0 and 1');
Expand All @@ -67,7 +67,7 @@ describe('mlKitLanguage() -> Language ID', () => {

it('throws an error if options.confidenceThreshold is greater than 1', async () => {
try {
firebase.mlKitLanguage().identifyLanguage('hello', { confidenceThreshold: 1.2 });
firebase.naturalLanguage().identifyLanguage('hello', { confidenceThreshold: 1.2 });
return Promise.reject(new Error('Did not throw'));
} catch (e) {
e.message.should.containEql('must be a float value between 0 and 1');
Expand All @@ -77,7 +77,7 @@ describe('mlKitLanguage() -> Language ID', () => {

it('throws an error if options.confidenceThreshold is less than 0', async () => {
try {
firebase.mlKitLanguage().identifyLanguage('hello', { confidenceThreshold: -1.2 });
firebase.naturalLanguage().identifyLanguage('hello', { confidenceThreshold: -1.2 });
return Promise.reject(new Error('Did not throw'));
} catch (e) {
e.message.should.containEql('must be a float value between 0 and 1');
Expand All @@ -88,7 +88,7 @@ describe('mlKitLanguage() -> Language ID', () => {

describe('identifyPossibleLanguages()', () => {
it('returns an array of the identified languages and their confidence', async () => {
const languages = await firebase.mlKitLanguage().identifyPossibleLanguages('hello');
const languages = await firebase.naturalLanguage().identifyPossibleLanguages('hello');
languages.should.be.an.Array();
languages.length.should.be.greaterThan(3);
languages[0].language.should.equal('en');
Expand All @@ -97,7 +97,7 @@ describe('mlKitLanguage() -> Language ID', () => {
});

it('accepts a `confidenceThreshold` option', async () => {
const languages = await firebase.mlKitLanguage().identifyPossibleLanguages('hello', {
const languages = await firebase.naturalLanguage().identifyPossibleLanguages('hello', {
confidenceThreshold: 0.7,
});
languages.should.be.an.Array();
Expand Down

0 comments on commit 2fddf9e

Please sign in to comment.