This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prepositions =['a','ante','bajo','cabe','con','contra','de','desde','en','entre','hacia','hasta','para','por','según','sin','so','sobre','tras'] | |
prep_alike = ['durante','mediante','excepto','salvo','incluso','más','menos'] | |
adverbs = ['no','si','sí'] | |
articles = ['el','la','los','las','un','una','unos','unas','este','esta','estos','estas','aquel','aquella','aquellos','aquellas'] | |
aux_verbs = ['he','has','ha','hemos','habéis','han','había','habías','habíamos','habíais','habían'] | |
tfid = TfidfVectorizer(stop_words=prepositions+prep_alike+adverbs+articles+aux_verbs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test = read_all_documents('examples2') | |
X_test = tfid.transform(test['docs']) | |
y_test = test['labels'] | |
pred = clf.predict(X_test) | |
print('accuracy score %0.3f' % clf.score(X_test, y_test)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.neighbors import KNeighborsClassifier | |
clf = KNeighborsClassifier(n_neighbors=3) | |
clf.fit(X_train, y_train) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.feature_extraction.text import TfidfVectorizer | |
X_train = tfid.fit_transform(documents) | |
y_train = labels |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = read_all_documents('examples') | |
documents = data['docs'] | |
labels = data['labels'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_all_documents(root): | |
labels = [] | |
docs = [] | |
for r, dirs, files in os.walk(root): | |
for file in files: | |
with open(os.path.join(r, file), "r") as f: | |
docs.append(f.read()) | |
labels.append(r.replace(root, '')) | |
return dict([('docs', docs), ('labels', labels)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<changeSet id="customer-005" author="joragupra"> | |
<comment>Delete columns for address information from customer table.</comment> | |
<dropColumn tableName="customer" columnName="street_name"/> | |
<dropColumn tableName="customer" columnName="street_number"/> | |
<dropColumn tableName="customer" columnName="postal_code"/> | |
<dropColumn tableName="customer" columnName="city"/> | |
<dropColumn tableName="customer" columnName="address_since"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer { | |
@Id | |
@GeneratedValue | |
private Long id; | |
@Column(name = "first_name") | |
private String firstName; | |
@Column(name = "last_name") | |
private String lastName; | |
@OneToMany(cascade = CascadeType.ALL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer { | |
... | |
public Address currentAddress() { | |
return addressHistory().stream().sorted(comparing(Address::addressSince).reversed()).findFirst().get(); | |
} | |
... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH caddresses_not_updated AS (SELECT c.* FROM customer c LEFT JOIN address a ON a.customer_id = c.id | |
WHERE (c.street_name IS NOT NULL OR c.street_number IS NOT NULL OR c.postal_code IS NOT NULL OR c.city IS NOT NULL) | |
AND a.id IS NOT NULL AND NOT exists(SELECT * FROM address a2 WHERE a2.customer_id = c.id AND a2.address_since > a.address_since) | |
AND c.address_since > a.address_since) | |
INSERT INTO address ( | |
id, | |
street_name, | |
street_number, | |
postal_code, | |
city, |
NewerOlder