Created
July 2, 2018 11:29
-
-
Save OsmanMutlu/f3b170800562d4b4cc012aeb2888552c to your computer and use it in GitHub Desktop.
This file contains 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
import pandas as pd | |
import re | |
import codecs | |
from glob import glob | |
from pynlpl.formats import folia | |
files = glob("alladjudicated/http*") | |
all_df = pd.DataFrame(files, columns=["filename"]) | |
all_df["text"] = "" | |
all_df["places"] = "" | |
def prep(row): | |
doc = folia.Document(file=row.filename) | |
row.text = doc.text() | |
places = [] | |
for i, sentence in enumerate(doc.sentences()): | |
for layer in sentence.select(folia.EntitiesLayer): | |
for entity in layer.select(folia.Entity): | |
if entity.cls == "place": | |
places.append(" ".join([word.text() for word in entity.wrefs() if word.text() != "village" or word.text() != "district"])) | |
row.places = places | |
return row | |
all_df = all_df.apply(prep,axis=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment