Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.     <title>Simple Natural Language Processing in JavaScript</title>
  9.     <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet" type="text/css">
  10.     <link href="https://unpkg.com/vuetify/dist/vuetify.min.css" rel="stylesheet" type="text/css">
  11.     <style>
  12.         #loader {
  13.             text-align: center;
  14.         }
  15.     </style>
  16. </head>
  17.  
  18. <body>
  19.  
  20.     <v-app id="app">
  21.         <v-toolbar class="grey lighten-4">
  22.             <v-toolbar-title class="grey--text text--darken-2">Natural Language Processing</v-toolbar-title>
  23.         </v-toolbar>
  24.         <main>
  25.             <v-container fluid>
  26.                 <v-layout row wrap>
  27.                     <v-flex xs12 sm12 md6 lg6 xl6>
  28.                         <v-text-field
  29.                        v-model="text"
  30.                        label="Type anything here..."
  31.                        multi-line
  32.                        rows="15"
  33.                        ></v-text-field>
  34.                         <v-select
  35.                            :items="actions"
  36.                            v-model="selected_action"
  37.                            label="Select Action"
  38.                            dark
  39.                            single-line
  40.                            auto
  41.                            ></v-select>
  42.                         <v-btn block class="blue darken-1 white--text" @click.native="compromise">Process</v-btn>
  43.                     </v-flex>
  44.                     <v-flex xs12 sm12 md6 lg6 xl6>
  45.                         <div id="loader" v-show="loader">
  46.                             <v-progress-circular indeterminate v-bind:size="60" class="primary--text"></v-progress-circular>
  47.                         </div>
  48.                         {{ output }}
  49.                     </v-flex>
  50.                 </v-layout>
  51.             </v-container>
  52.         </main>
  53.     </v-app>
  54.  
  55.     <script src="https://unpkg.com/vue/dist/vue.js"></script>
  56.     <script src="https://unpkg.com/vuetify/dist/vuetify.min.js"></script>
  57.     <script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>
  58.     <script>
  59.         var vm = new Vue({
  60.     el: "#app",
  61.     data: {
  62.         text: null,
  63.         output: null,
  64.         selected_action: null,
  65.         loader: false,
  66.         actions: ["Find all the people", "Grab the places", "Grab all verbs", "Show all the nouns", "Convert to number"]
  67.     },
  68.     methods: {
  69.         compromise() {
  70.             this.loader = true;
  71.             var action = this.selected_action;
  72.             var text = nlp(this.text);
  73.             if(this.selected_action == this.actions[0]) {
  74.                 var people = text.people();
  75.                 people.normalize();
  76.                 people.sort('frequency').unique();
  77.                 this.output = people.out('array'); // return them as an array
  78.                 this.loader = false;
  79.             }
  80.             else if (this.selected_action == this.actions[1]) {
  81.                 var places = text.places();
  82.                 places.sort('alpha').unique(); // sort alphabetically and dont repeat
  83.                 this.output = places.out('array'); // return them as an array
  84.                 this.loader = false;
  85.             }
  86.             else if (this.selected_action == this.actions[2]) {
  87.                 var verbs = text.match('#Verb');
  88.                 verbs.toUpperCase();
  89.                 this.output = verbs.out('array'); //return them as an array
  90.                 this.loader = false;
  91.             }
  92.             else if (this.selected_action == this.actions[3]) {
  93.                 var nouns = text.nouns();
  94.                 this.output = nouns.out('array'); //return them as an array
  95.                 this.loader = false;
  96.             }
  97.             else if (this.selected_action == this.actions[4]) {
  98.                 var num = text.values().toNumber();
  99.                 this.output = num.out('text')
  100.                 this.loader = false;
  101.             }
  102.            
  103.         }
  104.     }
  105. })
  106.     </script>
  107. </body>
  108.  
  109. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement