Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jusso-dev committed Apr 1, 2018
0 parents commit 7d42190
Show file tree
Hide file tree
Showing 56 changed files with 8,790 additions and 0 deletions.
1 change: 1 addition & 0 deletions BrainJSReactNative/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
3 changes: 3 additions & 0 deletions BrainJSReactNative/BrainJSReactNativeExampleApp/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
6 changes: 6 additions & 0 deletions BrainJSReactNative/BrainJSReactNativeExampleApp/.buckconfig
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 BrainJSReactNative/BrainJSReactNativeExampleApp/.flowconfig
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
53 changes: 53 additions & 0 deletions BrainJSReactNative/BrainJSReactNativeExampleApp/.gitignore
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
132 changes: 132 additions & 0 deletions BrainJSReactNative/BrainJSReactNativeExampleApp/App.js
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"
}
});
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;
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
}
}

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions BrainJSReactNative/BrainJSReactNativeExampleApp/__tests__/App.js
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 />
);
});
Loading

0 comments on commit 7d42190

Please sign in to comment.