Friday, March 30, 2018

Regular Expressions in Python

Regular Expressions in Python are very important in programming, Python "re" module provides regular expression support.

The re.search() method takes a regular expression pattern and a string and searches for that pattern within the string. If the search is successful, search() returns a match object or None otherwise. Therefore, the search is usually immediately followed by an if-statement to test if the search succeeded, as shown in the following example which searches for the pattern 'word:' followed by a 3 letter word (details below):

str = 'an example word:cat!!'
match = re.search(r'word:\w\w\w', str)
# If-statement after search() tests if it succeeded
  if match:                      
    print 'found', match.group() ## 'found word:cat'
  else:

    print 'did not find'

The code match = re.search(pat, str) stores the search result in a variable named "match". Then the if-statement tests the match -- if true the search succeeded and match.group() is the matching text (e.g. 'word:cat'). Otherwise if the match is false (None to be more specific), then the search did not succeed, and there is no matching text.


The 'r' at the start of the pattern string designates a python "raw" string which passes through backslashes without change which is very handy for regular expressions (Java needs this feature badly!). I recommend that you always write pattern strings with the 'r' just as a habit.

str = 'an example word:cat!!' match = re.search(r'word:\w\w\w', str) # If-statement after search() tests if it succeeded   if match:                           print 'found', match.group() ## 'found word:cat'   else:     print 'did not find'
str = 'an example word:cat!!' match = re.search(r'word:\w\w\w', str) # If-statement after search() tests if it succeeded   if match:                           print 'found', match.group() ## 'found word:cat'   else:     print 'did not find'
str = 'an example word:cat!!' match = re.search(r'word:\w\w\w', str) # If-statement after search() tests if it succeeded   if match:                           print 'found', match.group() ## 'found word:cat'   else:     print 'did not find'
str = 'an example word:cat!!' match = re.search(r'word:\w\w\w', str) # If-statement after search() tests if it succeeded   if match:                           print 'found', match.group() ## 'found word:cat'   else:     print 'did not find'


Thursday, March 29, 2018

Artificial Intelligence

AI (artificial intelligence) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning, reasoning  and self-correction.

Particular applications of AI include expert systems, speech recognition and machine vision.

Artificial intelligence can be implemented in the doamins like,

Healthcare:
The biggest bets are on improving patient outcomes and reducing costs. we can apply machine learning to make better and faster diagnoses than humans. AI applications may include chatbots, a computer program used online to answer questions and assist customers, to help schedule follow-up appointments or aiding patients through the billing process, and virtual health assistants that provide basic medical feedback.

Busines:
Robotic process automation is being applied to highly repetitive tasks normally performed by humans. Machine learning algorithms are being integrated into analytics and CRM platforms to uncover information on how to better serve customers.

Education:
AI can automate grading, giving educators more time. AI can assess students and adapt to their needs, helping them work at their own pace. AI tutors can provide additional support to students, ensuring they stay on track. AI could change where and how students learn, perhaps even replacing some teachers.

Finance:
AI applied to personal finance applications, such as Mint or Turbo Tax, is upending financial institutions. Applications such as these could collect personal data and provide financial advice. Other programs, IBM Watson being one, have been applied to the process of buying a home. Today, software performs much of the trading on Wall Street.

Law:
The discovery process, sifting through of documents, in law is often overwhelming for humans. Automating this process is a better use of time and a more efficient process. Startups are also building question-and-answer computer assistants that can sift programmed-to-answer questions by examining the taxonomy and ontology associated with a database.

Manufacturing: This is an area that has been at the forefront of incorporating robots into the workflow. Industrial robots used to perform single tasks and were separated from human workers, but as the technology advanced that changed.

Setting up local developement instance for Drupal 8

This blog is about set up a local developement instance for Drupal 8 on Pantheon server and the best use of drush.


Let’s follow the step-by-step process  to set up our own local developement instance:

I)

To set up local developement instancefor Drupal 8 ,  Click on git and copy below command
git clone ssh://devserver.dev.463157b8-419d-482f-b571-xxxxxxxxx@deveserver.dev.463157b8-419d-482f-b571-3504bb893903.drush.in:2222/~/repository.git mkrishnapriya-drupal

II)
Then go to your web root i.e. /var/www/html/ and paste the copied command
git clone ssh://devserver.dev.463157b8-419d-482f-b571-xxxxxxxxx@devserver.dev.463157b8-419d-482f-b571-3504bb893903.drush.in:2222/~/repository.mkrishnapriya-drupal
III)

Meanwhile, create a database for the site in local
mysql -u root -p Enter the username and administrator password you set-up during installation

CREATE DATABASE drupal8;
IV)
Download the Pantheon Drush alias from Pantheon Dashboard (https://dashboard.pantheon.io) and place that file to .drush folder
i.e. /home//.drush/

Place below code in .drush folder file name as local.aliases.drushrc.php
--------------------------------------------------------------------------

$local_sites = '/var/www/html/';
$scan = scandir($local_sites);
unset($scan[0]);
unset($scan[1]);
foreach($scan as $projects){
 $aliases[$projects] = array(
 'root' => $local_sites . $projects,
 'path-aliases' => array(
   '%dump-dir' => $local_sites . 'drush.dbdumps',
   '%files' => $local_sites . $projects . '/sites/default/files'
   )
 );
}
?>

V)
After clone is done, go to /var/www/html/drupal8/sites/default/
Create new settings.local.php should be an settings.local.php of Drupal 8 Note: Add below code snippet

/**
* @file
* settings.local.php.
*/
// Local development configuration.
if (!defined('PANTHEON_ENVIRONMENT')) {
 // Database.
 $databases['default']['default'] = array (
   'database' => Drupal8,
   'username' => '*****',
   'password' => '****',
   'prefix' => '',
   'host' => '******',
   'port' => '3306',
   'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
   'driver' => 'mysql',
 );
 $config_directories['sync'] = 'sites/default/config';
 $settings['hash_salt'] = '$HASH_SALT';
}
ini_set('max_execution_time', -1); // add if required
ini_set('memory_limit', '512M'); // add if required
ini_set('upload_max_filesize , 1024M'); // add if required
ini_set('post_max_size , 1024M'); // add if required

Step 6

Create files folder in sites/all/default/
Give permission to file folder Chmod 777 -R files/
Go to ./drush folder through terminal and type drush cc drush
Now on terminal, type drush sa
You will get all local aliases, dev aliases, test aliases and live aliases