예제 #1
0
import json
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
from application.models.spot import CitySpots
from pola.machine.topic_model.resource import PickleResource

if __name__ == "__main__":
    # for command line tool
    parser = argparse.ArgumentParser(description="Make corpus from tours data file.")
    parser.add_argument("--path", type=str, help="path to tour data file (json format).")
    args = parser.parse_args()

    # load tours data
    path = args.path
    if not path:
        path = os.path.join(os.path.dirname(__file__), "../data/spots.json")
    cityspots = CitySpots.load(path)

    # create city information data
    cityspotsj = []
    for cs in cityspots:
        j = {
            "id": cs.city.code,
            "spots": [s.code for s in cs.spots]
        }
        cityspotsj.append(j)

    # save as document
    cityspots_doc = CitySpots.to_doc(cityspots)

    print("show city spots corpus")
    cityspots_doc.show_vocab(limit=20)
예제 #2
0
 def load_city_spots(self, city_spot_ids):
     from application.models.spot import CitySpots
     spots = self.get_spots(city_spot_ids.spot_ids)
     cs = CitySpots(spot=spots[0])
     cs.spots = spots
     return cs