-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from /issues/150
Migration of config read to topicexplorer.config
- Loading branch information
Showing
7 changed files
with
99 additions
and
98 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
*.pyc | ||
sandbox | ||
config.* | ||
.coverage | ||
mprofile_* | ||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Apr 17 17:49:05 2016 | ||
@author: adi | ||
""" | ||
from __future__ import print_function | ||
from future import standard_library | ||
standard_library.install_aliases() | ||
from builtins import object | ||
from vsm import * | ||
from vsm.viewer.wrappers import doc_label_name | ||
|
||
import os.path | ||
from collections import defaultdict | ||
from configparser import ConfigParser as ConfigParser | ||
|
||
# load the topic models | ||
class keydefaultdict(defaultdict): | ||
""" Solution from: http://stackoverflow.com/a/2912455 """ | ||
def __missing__(self, key): | ||
if self.default_factory is None: | ||
raise KeyError( key ) | ||
else: | ||
ret = self[key] = self.default_factory(key) | ||
return ret | ||
|
||
# load in the configuration file | ||
class moduleLoad(object): | ||
|
||
def __init__(self,config_name): | ||
self.config_file = config_name | ||
#self.config_file = r"C:/Users/adi/Anaconda/topicexplorer/data23.ini" | ||
self.config = ConfigParser({ | ||
'topic_range': None, | ||
'topics': None}) | ||
self.config.read(self.config_file) | ||
self.lda_m = keydefaultdict(self.load_model) | ||
self.lda_v = keydefaultdict(self.load_viewer) | ||
|
||
# load the corpus | ||
def load_corpus(self): | ||
self.c = Corpus.load(self.config.get('main', 'corpus_file')) | ||
self.context_type = self.config.get('main', 'context_type') | ||
self.ctx_metadata = self.c.view_metadata(self.context_type) | ||
self.all_ids = self.ctx_metadata[doc_label_name(self.context_type)] | ||
from codecs import open | ||
from configparser import ConfigParser | ||
|
||
# create topic model patterns | ||
def create_model_pattern(self): | ||
self.pattern = self.config.get('main', 'model_pattern') | ||
if self.config.get('main', 'topics'): | ||
self.topic_range = eval(self.config.get('main', 'topics')) | ||
def read(filename): | ||
config = ConfigParser({ | ||
"htrc": False, | ||
"sentences": False, | ||
'certfile': None, | ||
'keyfile': None, | ||
'ca_certs': None, | ||
'ssl': False, | ||
'port': '8000', | ||
'host': '127.0.0.1', | ||
'icons': 'link', | ||
'corpus_link': None, | ||
'doc_title_format': '{0}', | ||
'doc_url_format': '', | ||
'raw_corpus': None, | ||
'label_module': None, | ||
'fulltext': False, | ||
'pdf' : False, | ||
'topics': None, | ||
'cluster': None, | ||
'corpus_desc' : None, | ||
'home_link' : '/', | ||
'lang' : None, | ||
'tokenizer': 'default' | ||
}) | ||
|
||
def load_model(self,k): | ||
if k in self.topic_range: | ||
return LdaCgsSeq.load(self.pattern.format(k)) | ||
else: | ||
raise KeyError("No model trained for k={}.".format(k)) | ||
def load_viewer(self,k): | ||
""" Function to dynamically load the LdaCgsViewer. | ||
Failure handling for missing keys is handled by `load_model`""" | ||
return LdaCgsViewer(self.c,self.lda_m[k]) | ||
with open(filename, encoding='utf8') as configfile: | ||
config.read_file(configfile) | ||
|
||
|
||
return config |
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
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
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