Exemplo n.º 1
0
    def __init__(self, **kwargs):
        super(JointSemanticModel, self).__init__(**kwargs)
        self.hyper_para = HyperParameter(**kwargs)
        self.external_resource = JointSemanticResource(**kwargs)

        self.ranking_model = None
        self.training_model = None
Exemplo n.º 2
0
 def __init__(self, **kwargs):
     super(Spotter, self).__init__(**kwargs)
     self.resource = JointSemanticResource(**kwargs)  # can be initialized here or by set_resource
     self.h_q_seg = dict()
     if self.pre_defined_segments:
         self.h_q_seg = json.load(open(self.pre_defined_segments))
         logging.info('loaded predefined segments')
Exemplo n.º 3
0
 def __init__(self, **kwargs):
     super(GroundCenter, self).__init__(**kwargs)
     assert self.grounder_name in self.h_name_grounder
     logging.info('use grounder [%s]', self.grounder_name)
     self.grounder = self.h_name_grounder[self.grounder_name](**kwargs)
     self.resource = JointSemanticResource(**kwargs)
     self.grounder.set_resource(self.resource)
Exemplo n.º 4
0
    def __init__(self, **kwargs):
        super(MatchCenter, self).__init__(**kwargs)
        self.resource = JointSemanticResource(**kwargs)
        self.h_q_info = dict()
        self.h_d_info = dict()
        self._load_qd_info()

        self.l_feature_extractor = []
        self._init_feature_extractors(**kwargs)
Exemplo n.º 5
0
 def __init__(self, **kwargs):
     super(BoeLeToRFeatureExtractCenter, self).__init__(**kwargs)
     self.resource = JointSemanticResource(**kwargs)
     self.l_extractor = []
     self.h_q_info = dict()
     self.h_doc_info = dict()
     self.h_qrel = dict()
     self._load_data()
     self._set_extractor(**kwargs)
Exemplo n.º 6
0
 def class_print_help(cls, inst=None):
     super(MatchCenter, cls).class_print_help(inst)
     JointSemanticResource.class_print_help(inst)
     for name, extractor_class in cls.h_group_mapping.items():
         print 'feature group:[%s]' % name
         extractor_class.class_print_help(inst)
Exemplo n.º 7
0
 def class_print_help(cls, inst=None):
     super(Spotter, cls).class_print_help()
     JointSemanticResource.class_print_help(inst)
Exemplo n.º 8
0
 def class_print_help(cls, inst=None):
     super(GroundCenter, cls).class_print_help(inst)
     JointSemanticResource.class_print_help(inst)
     for name, grounder_class in cls.h_name_grounder.items():
         print "grounder [%s]" % name
         grounder_class.class_print_help(inst)
Exemplo n.º 9
0
        l_sent = h_e_nlss.get(tail, [])
        l_aligned.append([edge, tail, {'nlss_sent': l_sent}])
    return l_aligned


def process(resource, out_name):
    out = open(out_name, 'w')
    for e, h_edge_info in resource.h_e_edge.items():
        l_edge = h_edge_info.get('edges', [])
        logging.info('aligning for [%s]', e)
        l_nlss = resource.l_h_nlss[0].get(e, [])
        h_aligned_info = align_per_entity(e, l_nlss, l_edge)
        print >> out, json.dumps(h_aligned_info)
    out.close()
    logging.info('finished')

if __name__ == '__main__':
    from knowledge4ir.utils import set_basic_log, load_py_config
    set_basic_log()
    if 3 != len(sys.argv):
        print "2 para: resource config + output"
        JointSemanticResource.class_print_help()
        sys.exit(-1)

    resource = JointSemanticResource(config=load_py_config(sys.argv[1]))
    process(resource, sys.argv[2])




Exemplo n.º 10
0

class AttBoeMainPara(Configurable):
    spotted_info_in = Unicode(help='spotted query or doc info').tag(
        config=True)
    out_name = Unicode(help='out name').tag(config=True)


if __name__ == '__main__':
    import sys
    from knowledge4ir.utils import (
        load_py_config,
        set_basic_log,
    )
    set_basic_log(logging.INFO)
    if 2 > len(sys.argv):
        print "config + spot in (opt) + out name (opt):"
        AttBoeMainPara.class_print_help()
        AttentionBoe.class_print_help()
        JointSemanticResource.class_print_help()
        sys.exit(-1)
    conf = load_py_config(sys.argv[1])
    main_para = AttBoeMainPara(config=conf)
    semantic_resource = JointSemanticResource(config=conf)
    boe_constructor = AttentionBoe(config=conf)
    boe_constructor.set_resource(semantic_resource)
    if len(sys.argv) < 4:
        boe_constructor.pipe_run(main_para.spotted_info_in, main_para.out_name)
    else:
        boe_constructor.pipe_run(sys.argv[2], sys.argv[3])
 def __init__(self, **kwargs):
     super(SpotSentAttention, self).__init__(**kwargs)
     self.resource = JointSemanticResource(**kwargs)
 def class_print_help(cls, inst=None):
     super(AppendText, cls).class_print_help(inst)
     JointSemanticResource.class_print_help(inst)
 def __init__(self, **kwargs):
     super(AppendText, self).__init__(**kwargs)
     self.resource = JointSemanticResource(**kwargs)
     self.h_qid_query = dict(load_qid_query(self.q_in))
     self.h_e_text = self.resource.h_entity_fields