Configuring IntelliJ IDEA for Electron

Standard

In the last blog post on Setting Up Electron Framework for Desktop Apps, we talked about Electron framework and its installation, we also tried a “Hello World” example in Electron. This post will a short one and will help you to configure Electron in an IDE – IntelliJ IDEA 2016.

Let’s get started with our configuration, first thing is making sure you are using JavaScript ECMAScript 6. Go to File > Settings > Languages and Frameworks > JavaScript and select ECMAScript 6. Now we need to install the JavaScript library for Electron called github-electron-DefinitelyTyped. This can be done by heading over to,

File > Settings > Languages and Frameworks > JavaScript > Libraries > (Select) Download.

After all the libraries are loaded search for github-electron-DefinitelyTyped  and download and install it. After that check / select that library.

settings_007

To enable “Coding Assistance” go to File > Settings > Languages and Frameworks > Node.js and NPM > Enable the Coding Assistance for Node.js Core Library.

Run/Debug Configuration:

Select a Node.js run configuration. In the Node interpreter, give the path to the Electron executable. Also, in JavaScript file field give the path your main JavaScript file in the project and save this configuration and Run.

run-debug-configurations_008

Here’s a great Material Design desktop app I made with Electron Framework. In case you are wondering, I used Material Design Lite library for Material Design components.

This slideshow requires JavaScript.

Fork this app on Github:

image4233

Read my other post on Setting Up Electron Framework for Desktop Apps. Download the best IDE in town here at JetBrains IntelliJ IDEA.

Advertisements

Setting up Electron framework for Desktop apps

Standard

So, I recently came across a bunch beautifully designed and developed desktop apps on my Linux. Now, as a Linux user, I am used to overlooking design and aesthetics over functionality. Linux desktop developers usually don’t spend their energy on making their apps more user-friendly and appealing instead they invest it in improving its functionality. And it is generally assumed by them that the user is someone who is well versed in Linux Vedas and can handle the “rugged” nature of their desktop apps. But this notion is slowly changing with the introduction of new cross-platform desktop application frameworks like Electron. I have been using a few Electron apps for a couple of months now and I will just leave it to you to decide how aesthetically pleasing they are.

This slideshow requires JavaScript.

What is Electron ?

Electron is an open source library developed by GitHub for building cross-platform desktop applications with HTML, CSS, and JavaScript. Electron accomplishes this by combining Chromium and Node.js into a single runtime and apps can be packaged for Mac, Windows, and Linux.

Want to build cross-platform desktop applications ? Here’s how you go about setting up Electron in Linux.
First, we install npm to manage Node.js packages :

$ sudo apt-get install npm

Then we install Node.js :

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Finally, we install Electron package. This command installs Electron globally but you can install it locally for your project.

$ sudo npm install -g electron

Now that we have installed Electron let us try a “Hello World” example as a part of our initiation ceremony! Any Electron app source code primarily has three important components, the JavaScript, the HTML (CSS optional) and the JSON file called package.json.

This package.json file is important with respect to Electron to define the app name, version and its main process, which usually is the JavaScript (index.js).

{
  "name" : "Hello World",
  "version" : "0.1.0",
  "main" : "main.js"
}

The JavaScrip file consists of all the Electron APIs and it is necessary to define const {app, BrowserWindow} = require('electron') in the .js file to include the Electron APIs. In this file you can include the rest of your app’s specific main process code. You can also put them in separate files and require them here.

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({width: 800, height: 600})

  // and load the index.html of the app.
  win.loadURL(`file://${__dirname}/index.html`)

  // Open the DevTools.
  win.webContents.openDevTools()

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null
  })
}

The BrowserWindow object creates a Window using the given width and height dimensions. When Electron has finished initialization and is ready to create browser windows we call the  app.on('ready', createWindow) method. Some APIs can only be used after this event occurs.
At last, we define the HTML tags we want to use in our index.html file and design our app as per our requirements. In this example, we will stick to the h1 tag.
To execute our Electron app, go to the project directory and execute with the electron command:

$ electron .
hello-world_006

Hello World – Electron App running on Linux Mint 18

Download the Hello World example here:

image4233

Further Readings :

Let me know your thoughts and experiments with Electron in the comments section below.

Setting up Natural Language Processing Environment with Python

Standard

In this blog post, I will be discussing all the tools of Natural Language Processing pertaining to Linux environment, although most of them would also apply to Windows and Mac. So, let’s get started with some prerequisites.
We will use Python’s Pip package installer in order to install various python modules.

$ sudo apt install python-pip
$ pip install -U pip
$ pip install --upgrade pip

So I am going to talk about three NLP tools in Python that I have worked with so far.

Note: It is highly recommended to install these modules in a Virtual Environment. Here is how you do that : Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages.

  1. Natural Language Toolkit :

    NLTK can be seen as a library written for educational purposes and hence, is great to experiment with as its website itself notes this; NLTK has been called “a wonderful tool for teaching, and working in, computational linguistics using Python,” and “an amazing library to play with natural language.” To install NLTK we use pip :

    $ sudo pip install -U nltk

    NLTK also comes with its own corpora and can be downloaded as follows:

    >>> import nltk
    >>> nltk.download()

    felixfelix-_010
    We can also interface NLTK with our own corpora. For detailed usage of the NLTK API usage, one can refer its official guide “Natural Language Processing with Python by Steven Bird”. I will be covering more about NLTK its API usage in the upcoming posts, but for now, we will settle with its installation.

  2. spaCy :

    In the words of Matthew Honnibal (author of spaCy);

    ” There’s a real philosophical difference between spaCy and NLTK. spaCy is written to help you get things done. It’s minimal and opinionated. We want to provide you with exactly one way to do it — the right way. In contrast, NLTK was created to support education. Most of what’s there is for demo purposes, to help students explore ideas. spaCy provides very fast and accurate syntactic analysis (the fastest of any library released), and also offers named entity recognition and ready access to word vectors. You can use the default word vectors, or replace them with any you have.

    What really sets it apart, though, is the API. spaCy is the only library that has all of these features together, and allows you to easily hop between these levels of representation. Here’s an example of how that helps. Tutorial: Search Reddit for comments about Google doing something . spaCy also ensures that the annotations are always aligned to the original string, so you can easily print mark-up: Tutorial: Mark all adverbs, particularly for verbs of speech . “

    The benchmarks provided on its official website:selection_011
    Here are some of the things I have tried with spaCy and it’s my favorite NLP tool. In the upcoming posts I will dwell into each of its APIs so, keep an eye out here (spaCy):selection_004
    Installation :

    $ sudo pip install -U spacy
    $ sudo python -m spacy.en.download

    What makes it easy to work with spaCy is it’s well maintained and presented documentation. They also have made some great demos like displaCy for dependency parser and named entity recognizer. Check them out here.

  3. TextBlob :

    It is more of a text processing library than an NLP library. It is simple and light weight and is your go-to library when you have to perform some basic NLP operations such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.
    Installation :

    $ sudo pip install -U textblob
    $ sudo python -m textblob.download_corpora

    Usage to check word definitions and synonyms and similarity between different words. I will be doing an independent post on TexBlob with WordNet and its SynSets:selection_013

Check out my other posts on Natural Language Processing.

Further Reading :

If you have any problem with installations or some other comments let me know below in the comments section. Meanwhile, you can also check out my other post on Machine Learning Classification algorithm. Naive Bayes Classifier in Python