def _create_analysis_page(article, dataset):
    assert(isinstance(article, Article))

    article_name = article.name
    processed_sentences = article.processed_sentences
    
    if dataset is None:
        metadata = article.metadata
        print 'metadata:', metadata
        
        title = metadata.get('full_title')
        nlen = min(45, len(title))
        title = title[:nlen]
        year = metadata.get('publ_year')
        author = metadata.get('prim_author')

        hdr = '<b>%s</b>, <b>Title:</b> %s, <b>Author:</b> %s, <b>Date:</b> %s, <b># of Sentences:</b> %d' \
            % (article_name, title, author, year, len(processed_sentences)) 
        html = hdr

    elif dataset == ANALYSIS_CL_CONTENT:
        html = article.raw_html

    elif dataset == ANALYSIS_ORIG_CONTENT:
        original_content_path = os.path.join(helper.get_root_dir(), article.metadata['rel_content_path'])
        html = open(original_content_path, 'r').read()

    elif dataset == ANALYSIS_WORDNET_DEFS:
        wd_cnts = rc.get_word_counts(article.word_counts, mincnt=5)
        terms = wd_cnts.keys()
        # ignore bigrams or more
        terms = filter(lambda t: ' ' not in t, terms)
        
        unidentified = rc.get_unk_wds(terms)
        unidentified_html_ = ['%s<b>%s</b> - %s' % ('', unk, wd_cnts[unk]) for unk in unidentified]
        unidentified_html = ', '.join(unidentified_html_)
        
        indent = 4*'&nbsp;'
        terms_w_defs = rc.get_wd_defs(terms)
        identified_html = ''
        for wd in terms_w_defs:
            wordnet_defs = terms_w_defs[wd]
            identified_html += '<br><b>%s</b> - %s<br>%s%s<br>' \
                  % (wd, wd_cnts[wd], indent, ('<br>'+indent).join(wordnet_defs))
        html = '''
<div id="unidentified_terms"><i><u>Unidentified terms</u></i><br>%s</div><br>
<div id="identified_terms"><i><u>Wordnet Definitions</u></i><br>%s</div> 
''' % (unidentified_html, identified_html)

    elif dataset == ANALYSIS_WORD_CNTS:
        word_cnts = rc.get_word_counts(article.word_counts, mincnt=5)

        # Why am I making this a string? Need to do this for the sake
        # of JSON serialization issues...
        word_cnts = dict([(c, repr(word_cnts[c])) for c in word_cnts.keys()])
        
        #wcs.reverse()
        #html = ' '.join(['(%s: %s)' % (r[0], r[1]) for r in wcs])
        #wcs = dict(wcs)
        
        # working on this will just be something cute, but really should try
        # and get to something more meaningful, textually?  
        json_rslt = json.dumps(word_cnts, ensure_ascii=False)

        # Need to create JSON and then page
        html = json_rslt

    elif dataset == ANALYSIS_NER_ST:
        named_entities = article.get_ner_results(ner='ST')
        html = '<div>%s %s</div>' % (NER_ST_LEGEND, named_entities)

    elif dataset == ANALYSIS_NER_MA:
        named_entities = article.get_ner_results(ner='MA')
        html = '<div>%s %s</div>' % (NER_MA_LEGEND, named_entities)

    else:
        html = ''
    
    return html
示例#2
0
from gym_minigrid.wrappers import FullyObsWrapper

from agent.learning.learner import TabularLearner, CustomRewardTabularLearner, train_mult_steps
from agent.learning.policy import EpsilonGreedyPolicy
from helper import get_root_dir
import minigrid_envs

from agent.detection.minigrid_detector import MiniGridDetector
from agent.execution.minigrid_executor import MiniGridExecutor
from agent.solver import Solver

from agent.env_wrappers import NamedObjectWrapper, LastObsWrapper, RewardsWrapper, UnitRewardWrapper
from agent.statehashing.minigrid_hashing import MinigridStateHasher

ROOT_DIR = get_root_dir()

logging.basicConfig(
    filename=ROOT_DIR + "/logs/console.log",
    format="%(asctime)s — %(name)s — %(levelname)s — %(message)s",
    filemode='w')

# Creating an object
log = logging.getLogger("Experiment")

# Setting the threshold of logger to DEBUG
log.setLevel(logging.DEBUG)

NUM_TO_NAME_AND_GOAL = {
    '1': ("MiniGrid-SpotterLevel1-v0", "(open door)"),
    '2': ("MiniGrid-SpotterLevel2-v0", "(open door)"),
示例#3
0
import logging

from agent.execution_mode import ExecutionMode
from agent.exploration_mode import ExplorationMode
from agent.planning.forward_search import ForwardSearch
from agent.mode import Mode
from representation.task import state_subsumes

from helper import get_root_dir
logging.basicConfig(filename=get_root_dir() + "/logs/console.log",
                    format="%(name)s — %(levelname)s — %(message)s",
                    filemode='w')
log = logging.getLogger("planning_mode")
log.setLevel(logging.DEBUG)


class PlanningMode(Mode):
    """
    Planning mode
    """
    def __init__(self, brain, planner="bfs"):
        super().__init__(brain)
        self.name = "Planning Mode"
        self.planner = planner
        self.plan_exists = False

    def _run(self):
        # TODO implement plan caching and unplannability caching in the planning mode so we don't have to
        #  replan every time.
        if self.planner == "bfs":
            # bfs = BFS()
示例#4
0
import gym
import logging

from agent.solver import Solver
from agent.execution.cupsworld_executor import CupsWorldExecutor
from agent.detection.cupsworld_detector import CupsWorldDetector

from helper import get_root_dir
logging.basicConfig(
    filename=get_root_dir() + "/logs/console.log",
    format="%(asctime)s — %(name)s — %(levelname)s — %(message)s",
    filemode='w')

# Creating an object
log = logging.getLogger("Experiment")

# Setting the threshold of logger to DEBUG
log.setLevel(logging.DEBUG)


class Experiment:
    def __init__(self):
        pass

    def run(self):
        env = gym.make('CupsWorld-v0')
        domain = "domains/domain.pddl"
        domain_incorrect = "domains/domain_incorrect.pddl"
        goals = []
        goals.append("(on block_blue block_red)")
        goals.append("(on block_red cup)")