Python: Read Write JSON

In this article, I will be showing how to read data from a JSON file and write data to a new JSON file using Python programming language. Suppose, I have the following JSON data which is saved in a file named sample-1.json. Download: sample-1.json {"votes": {"funny": 25, "useful": 59, "cool": 29}, "user_id": "1", "name": "User … Read more

Magento 2: Set Unset Get Session

This article shows how to create and destroy different types (Checkout, Customer, Catalog) of sessions in Magento 2. As you can see below, there are different types of session classes present in Magento 2. vendor/magento/module-catalog/Model/Session.php vendor/magento/module-newsletter/Model/Session.php vendor/magento/module-persistent/Model/Session.php vendor/magento/framework/Message/Session.php vendor/magento/module-customer/Model/Session.php vendor/magento/module-backend/Model/Session.php vendor/magento/module-checkout/Model/Session.php In below example code, I will be dealing with Catalog, Customer, and Checkout sessions. … Read more

Magento 2: Get Current URL & Base URL

This article shows how we can get current and base URL in Magento 2. Both Dependency Injection and Object Manager ways of coding are given below. Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of StoreManagerInterface & UrlInterface in the constructor of my module’s block … Read more

Python: Read Write CSV

In this article, I will be showing how to read data from a CSV file and write data to a new CSV file using Python programming language. Here’s a scenario: Suppose, I have a CSV file with 3 columns (user_id, item_id, and star_rating). It has data of 100 users. Each user has rated 20 different … Read more

Magento 2: Get Current Category & Current Product

This article shows how we can get current category and current product data in Magento 2. Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\Registry class in the constructor of my module’s block class. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; class HelloWorld extends \Magento\Framework\View\Element\Template { protected $_registry; public function __construct( … Read more

Python: Graph plotting with Matplotlib (Bar Chart)

This article deals with plotting line graphs with Matplotlib (a Python’s library). Below is the data which we will use to plot the bar chart. The data is saved in a CSV file named result3-blog.csv. As seen above, the CSV file contains result in terms of F1 measure which is an accuracy measure generally used … Read more

Magento 2: Writing Custom Log

In Magento 1, you could simply write your own custom log with the following code: Mage::log("Your Log Message", null, "your_log_file.log"); and it would be saved at MAGENTO_ROOT/var/log/your_log_file.log However, it’s not that simple and quite different in Magento 2. As Magento 2 uses dependency injection design pattern, you need to pass the logger instance through the … Read more

Python: Graph plotting with Matplotlib (Line Graph)

This article deals with plotting line graphs with Matplotlib (a Python’s library). In the article Machine Learning & Sentiment Analysis: Text Classification using Python & NLTK, I had described about evaluating three different classifiers’ accuracy using different feature sets. In this article, I will be using the accuracy result data obtained from that evaluation. Below … Read more

Machine Learning & Sentiment Analysis: Text Classification using Python & NLTK

This article deals with using different feature sets to train three different classifiers [Naive Bayes Classifier, Maximum Entropy (MaxEnt) Classifier, and Support Vector Machine (SVM) Classifier]. Bag of Words, Stopword Filtering and Bigram Collocations methods are used for feature set generation. Text Reviews from Yelp Academic Dataset are used to create training dataset. Cross-validation is … Read more