-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7d42190
Showing
56 changed files
with
8,790 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["react-native"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
[android] | ||
target = Google Inc.:Google APIs:23 | ||
|
||
[maven_repositories] | ||
central = https://repo1.maven.org/maven2 |
54 changes: 54 additions & 0 deletions
54
BrainJSReactNative/BrainJSReactNativeExampleApp/.flowconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[ignore] | ||
; We fork some components by platform | ||
.*/*[.]android.js | ||
|
||
; Ignore "BUCK" generated dirs | ||
<PROJECT_ROOT>/\.buckd/ | ||
|
||
; Ignore unexpected extra "@providesModule" | ||
.*/node_modules/.*/node_modules/fbjs/.* | ||
|
||
; Ignore duplicate module providers | ||
; For RN Apps installed via npm, "Libraries" folder is inside | ||
; "node_modules/react-native" but in the source repo it is in the root | ||
.*/Libraries/react-native/React.js | ||
|
||
; Ignore polyfills | ||
.*/Libraries/polyfills/.* | ||
|
||
; Ignore metro | ||
.*/node_modules/metro/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
node_modules/react-native/Libraries/react-native/react-native-interface.js | ||
node_modules/react-native/flow/ | ||
node_modules/react-native/flow-github/ | ||
|
||
[options] | ||
emoji=true | ||
|
||
module.system=haste | ||
|
||
munge_underscores=true | ||
|
||
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' | ||
|
||
module.file_ext=.js | ||
module.file_ext=.jsx | ||
module.file_ext=.json | ||
module.file_ext=.native.js | ||
|
||
suppress_type=$FlowIssue | ||
suppress_type=$FlowFixMe | ||
suppress_type=$FlowFixMeProps | ||
suppress_type=$FlowFixMeState | ||
|
||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError | ||
|
||
[version] | ||
^0.65.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -text |
53 changes: 53 additions & 0 deletions
53
BrainJSReactNative/BrainJSReactNativeExampleApp/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
*.keystore | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/ | ||
|
||
*/fastlane/report.xml | ||
*/fastlane/Preview.html | ||
*/fastlane/screenshots |
1 change: 1 addition & 0 deletions
1
BrainJSReactNative/BrainJSReactNativeExampleApp/.watchmanconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { Component } from 'react'; | ||
import { | ||
Platform, | ||
StyleSheet, | ||
Text, | ||
View, | ||
TextInput, | ||
TouchableOpacity | ||
} from 'react-native'; | ||
import classify from './Services/classify-service.js' | ||
import Header from './Components/header.js' | ||
|
||
export default class App extends Component { | ||
|
||
constructor() { | ||
super() | ||
|
||
this.state = { | ||
DrakeResult:"", | ||
EminemResult:"", | ||
DrakeResultColor:"lightgreen", | ||
EminemResultColor:"red", | ||
resultShow:0 | ||
} | ||
} | ||
|
||
ClassifyText = () => { | ||
|
||
let drakesScore = classify.classifyLyrics(this.state.lyrics) | ||
let eminmeScore = classify.classifyLyrics(this.state.lyrics) | ||
|
||
if(drakesScore === NaN || drakesScore === null || eminmeScore === NaN || eminmeScore === null) { | ||
this.setState({ | ||
DrakeResult:"Unable to determine confidence level.", | ||
EminemResult:"Unable to determine confidence level.", | ||
resultShow:100 | ||
}) | ||
return; | ||
} | ||
|
||
if(drakesScore > eminmeScore) { | ||
this.setState({ | ||
DrakeResultColor:'lightgreen', | ||
EminemResultColor:'red' | ||
}) | ||
} else { | ||
this.setState({ | ||
DrakeResultColor:'red', | ||
EminemResultColor:'lightgreen' | ||
}) | ||
} | ||
|
||
this.setState({ | ||
DrakeResult:classify.classifyLyrics(this.state.lyrics).Drake, | ||
EminemResult:classify.classifyLyrics(this.state.lyrics).Eminem, | ||
resultShow:100 | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Header /> | ||
<Text style={styles.inputLyricsTextLable}>Input Lyrics:</Text> | ||
<TextInput | ||
style={{height: 150, borderColor: '#F3DF4A', borderWidth: 2}} | ||
onChangeText={(lyrics) => this.setState({lyrics})} | ||
multiline = {true} | ||
/> | ||
<TouchableOpacity | ||
style={styles.classifyBtnStyle} | ||
onPress={() => this.ClassifyText()} | ||
underlayColor='#F3DF4A'> | ||
<Text style={styles.classifyTextStyle}>Classify</Text> | ||
</TouchableOpacity> | ||
|
||
<Text style={{ | ||
fontSize:16, | ||
fontWeight:"bold", | ||
textAlign:"center", | ||
marginTop:"10%", | ||
marginTop:50, | ||
paddingTop:10, | ||
paddingBottom:10, | ||
backgroundColor:this.state.DrakeResultColor, | ||
opacity:this.state.resultShow | ||
}}> | ||
Drake: {this.state.DrakeResult} | ||
</Text> | ||
<Text style={{ | ||
fontSize:16, | ||
fontWeight:"bold", | ||
textAlign:"center", | ||
paddingTop:10, | ||
paddingBottom:10, | ||
backgroundColor:this.state.EminemResultColor, | ||
opacity:this.state.resultShow | ||
}}> | ||
Eminem: {this.state.EminemResult} | ||
</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
}, | ||
inputLyricsTextLable: { | ||
fontWeight:"bold", | ||
fontSize:16, | ||
textAlign:"center", | ||
marginTop:"35%", | ||
marginBottom:"5%" | ||
}, | ||
classifyBtnStyle: { | ||
marginRight:40, | ||
marginLeft:40, | ||
marginTop:10, | ||
paddingTop:10, | ||
paddingBottom:10, | ||
backgroundColor:'#F3DF4A', | ||
borderRadius:10, | ||
borderWidth: 1, | ||
borderColor: '#fff' | ||
}, | ||
classifyTextStyle: { | ||
fontSize:16, | ||
fontWeight:"bold", | ||
textAlign:"center" | ||
} | ||
}); |
30 changes: 30 additions & 0 deletions
30
BrainJSReactNative/BrainJSReactNativeExampleApp/Components/header.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { Component } from 'react'; | ||
import { | ||
Platform, | ||
StyleSheet, | ||
Text, | ||
View | ||
} from 'react-native'; | ||
|
||
export class Header extends Component { | ||
render() { | ||
return( | ||
<View> | ||
<Text style={styleSheet.header}>brain.js 🤖 - React Native Example</Text> | ||
</View> | ||
) | ||
} | ||
} | ||
|
||
const styleSheet = StyleSheet.create({ | ||
header: { | ||
backgroundColor: "#F3DF4A", | ||
padding:"10%", | ||
flex:1, | ||
fontWeight:"bold", | ||
fontSize:16, | ||
textAlign:"center" | ||
} | ||
}) | ||
|
||
export default Header; |
28 changes: 28 additions & 0 deletions
28
BrainJSReactNative/BrainJSReactNativeExampleApp/Services/classify-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const brain = require('brain.js') | ||
const json = require('./trained-model') | ||
|
||
export default classify = { | ||
|
||
classifyLyrics(inputText) { | ||
|
||
if(inputText == undefined || inputText == null) { | ||
return null; | ||
} | ||
|
||
//credit - Daniel Simmons - https://itnext.io/you-can-build-a-neural-network-in-javascript-even-if-you-dont-really-understand-neural-networks-e63e12713a3 | ||
|
||
let trainedNet; | ||
|
||
var net = new brain.NeuralNetwork() | ||
|
||
net.fromJSON( | ||
json | ||
); | ||
|
||
function encode(arg) { | ||
return arg.split('').map(x => (x.charCodeAt(0) / 256)); | ||
} | ||
let results = net.run(encode(inputText)); | ||
return results | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
BrainJSReactNative/BrainJSReactNativeExampleApp/Services/trained-model.json
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
BrainJSReactNative/BrainJSReactNativeExampleApp/__tests__/App.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'react-native'; | ||
import React from 'react'; | ||
import App from '../App'; | ||
|
||
// Note: test renderer must be required after react-native. | ||
import renderer from 'react-test-renderer'; | ||
|
||
it('renders correctly', () => { | ||
const tree = renderer.create( | ||
<App /> | ||
); | ||
}); |
Oops, something went wrong.