Skip to content

Commit

Permalink
Added the first NLP tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
neubig committed May 31, 2014
0 parents commit 91da548
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 0 deletions.
Binary file added 00-intro/nlp-programming-en-00-intro.odp
Binary file not shown.
Binary file added 00-intro/nlp-programming-en-00-intro.pdf
Binary file not shown.
Binary file added 00-intro/nlp-programming-ja-00-intro.odp
Binary file not shown.
Binary file added 00-intro/nlp-programming-ja-00-intro.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions 00-intro/sample-code/00-hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
cout << "Hello World!" << endl;
}
4 changes: 4 additions & 0 deletions 00-intro/sample-code/00-hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/python
print "Hello World!"


14 changes: 14 additions & 0 deletions 00-intro/sample-code/01-datatypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char** argv) {
int my_int = 4;
double my_float = 2.5;
string my_string = "hello";

cout << "string: " << my_string // Print the string
<< "\tfloat: " << my_float // Print the float
<< "\tint: " << my_int // Print the int
<< endl; // Print the end of the line
}
9 changes: 9 additions & 0 deletions 00-intro/sample-code/01-datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/python

my_int = 4
my_float = 2.5
my_string = "hello"

print "string: %s\tfloat: %f\tint: %d" % (my_string, my_float, my_int)


18 changes: 18 additions & 0 deletions 00-intro/sample-code/02-iffor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char** argv) {
int my_variable = 5;

if(my_variable == 4) {
cout << "my_variable is 4" << endl;
} else {
cout << "my_variable is not 4" << endl;
}

for(int i = 1; i < 5; i++) {
cout << "i == " << i << endl;
}

}
11 changes: 11 additions & 0 deletions 00-intro/sample-code/02-iffor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/python

my_variable = 5

if my_variable == 4:
print "my_variable is 4"
else:
print "my_variable is not 4"

for i in range(1, my_variable):
print "i == %d" % (i)
24 changes: 24 additions & 0 deletions 00-intro/sample-code/03-array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
using namespace std;

int main(int argc, char** argv) {
vector<int> my_list(5);
my_list[0] = 1;
my_list[1] = 2;
my_list[2] = 4;
my_list[3] = 8;
my_list[4] = 16;

my_list.push_back(32);

cout << my_list.size() << endl;

cout << my_list[3] << endl << endl;

BOOST_FOREACH(int value, my_list) {
cout << value << endl;
}

}
16 changes: 16 additions & 0 deletions 00-intro/sample-code/03-array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/python

my_list = [1, 2, 4, 8, 16]

my_list.append(32)

print len(my_list)

print my_list[3]
print ""

for value in my_list:
print value



29 changes: 29 additions & 0 deletions 00-intro/sample-code/04-keyvalue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <string>
#include <boost/tr1/unordered_map.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace std::tr1;

int main(int argc, char** argv) {
unordered_map<string,int> my_dict;
my_dict["alan"] = 22;
my_dict["bill"] = 45;
my_dict["chris"] = 17;
my_dict["dan"] = 27;

my_dict["eric"] = 33;

cout << my_dict.size() << endl;

cout << my_dict["chris"] << endl << endl;

// Boost foreach can not use pairs directly, so we must define a type
// StringIntPair
typedef pair<string,int> StringIntPair;

BOOST_FOREACH(StringIntPair key_value, my_dict) {
cout << key_value.first << " --> " << key_value.second << endl;
}

}
17 changes: 17 additions & 0 deletions 00-intro/sample-code/04-keyvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python

my_dict = {"alan": 22, "bill": 45, "chris": 17, "dan": 27}

my_dict["eric"] = 33

print len(my_dict)
print my_dict["chris"]

if "dan" in my_dict:
print "dan exists in my_dict"

for foo, bar in sorted(my_dict.items()):
print "%s --> %r" % (foo, bar)



16 changes: 16 additions & 0 deletions 00-intro/sample-code/04a-keyvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/python

from collections import defaultdict

my_dict = defaultdict(lambda: 0)

my_dict["eric"] = 33

print my_dict["eric"]
print my_dict["fred"]

for foo, bar in sorted(my_dict.items()):
print "%s --> %r" % (foo, bar)



21 changes: 21 additions & 0 deletions 00-intro/sample-code/05-split.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace boost;

int main(int argc, char** argv) {

string sentence = "this is a pen";
vector<string> words;
split(words, sentence, is_any_of(" "));

BOOST_FOREACH(string word, words) {
cout << word << endl;
}

cout << boost::algorithm::join(words, " ||| ") << endl;

}
11 changes: 11 additions & 0 deletions 00-intro/sample-code/05-split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/python

import string

sentence = "this is a pen"
words = sentence.split(" ")

for word in words:
print word

print string.join(words, " ||| ")
14 changes: 14 additions & 0 deletions 00-intro/sample-code/06-function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
using namespace std;

int add_and_abs(int x, int y) {
int z = x + y;
if(z >= 0)
return z;
else
return z * -1;
}

int main(int argc, char** argv) {
cout << add_and_abs(-4, 1) << endl;
}
19 changes: 19 additions & 0 deletions 00-intro/sample-code/06-function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python

def add_and_abs(x, y):
z = x + y
if z >= 0:
return z
else:
return z * -1

def test_add_and_abs():
if add_and_abs(3, 1) != 4:
print "add_and_abs(3, 1) != 4 (== %d)" % add_and_abs(3, 1)
return 0
if add_and_abs(-4, 1) != 3:
print "add_and_abs(-4, 1) != 3 (== %d)" % add_and_abs(-4, 1)
return 0
return 1

print test_add_and_abs()
13 changes: 13 additions & 0 deletions 00-intro/sample-code/07-readfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char** argv) {
ifstream my_file(argv[1]);
string line;
while(getline(my_file, line)) {
if(line.length() != 0) {
cout << line << endl;
}
}
}
11 changes: 11 additions & 0 deletions 00-intro/sample-code/07-readfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/python

import sys
my_file = open(sys.argv[1], "r")

for line in my_file:

line = line.strip()

if len(line) != 0:
print line

0 comments on commit 91da548

Please sign in to comment.