当前位置: 首页>>代码示例>>Python>>正文


Python IdSet.write方法代码示例

本文整理汇总了Python中Core.IdSet.IdSet.write方法的典型用法代码示例。如果您正苦于以下问题:Python IdSet.write方法的具体用法?Python IdSet.write怎么用?Python IdSet.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Core.IdSet.IdSet的用法示例。


在下文中一共展示了IdSet.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ids

# 需要导入模块: from Core.IdSet import IdSet [as 别名]
# 或者: from Core.IdSet.IdSet import write [as 别名]
class ExampleBuilder:
    structureAnalyzer = None
    """ 
    ExampleBuilder is the abstract base class for specialized example builders.
    Example builders take some data and convert it to examples usable by e.g. SVMs.
    An example builder writes three files, an example-file (in extended Joachim's
    SVM format) and .class_names and .feature_names files, which contain the names
    for the class and feature id-numbers. An example builder can also be given
    pre-existing sets of class and feature ids (optionally in files) so that the
    generated examples are consistent with other, previously generated examples.
    """    
    def __init__(self, classSet=None, featureSet=None):
        if(type(classSet) == types.StringType):
            self.classSet = IdSet(filename=classSet)
        else:
            self.classSet = classSet
        
        if(type(featureSet) == types.StringType):
            self.featureSet = IdSet(filename=featureSet)
        else:
            self.featureSet = featureSet
        
        self.featureTag = ""      
        self.exampleStats = ExampleStats()
        self.parse = None
        self.tokenization = None
        #self.idFileTag = None
        self.classIdFilename = None
        self.featureIdFilename = None
        
        self.styles = None
        self._defaultParameters = None
        self._parameterValueLimits = None
        self._setDefaultParameters(["sentenceLimit"])
        self.debug = False
    
    def _setDefaultParameters(self, defaults=None, valueLimits=None):
        # Initialize
        if self._defaultParameters == None:
            self._defaultParameters = {}
        if self._parameterValueLimits == None:
            self._parameterValueLimits = {}
        newParameters = Utils.Parameters.get({}, defaults, valueLimits=valueLimits)
        self._defaultParameters.update(newParameters)
        if valueLimits != None:
            self._parameterValueLimits.update(valueLimits)
    
    def getParameters(self, parameters):
        return Utils.Parameters.get(parameters, defaults=self._defaultParameters, valueLimits=self._parameterValueLimits)
    
    def setFeature(self, name, value):
        self.features[self.featureSet.getId(self.featureTag+name)] = value
    
    def getElementCounts(self, filename):
        print >> sys.stderr, "Counting elements:",
        if filename.endswith(".gz"):
            f = gzip.open(filename, "rt")
        else:
            f = open(filename, "rt")
        counts = {"documents":0, "sentences":0}
        for line in f:
            if "<document" in line:
                counts["documents"] += 1
            elif "<sentence" in line:
                counts["sentences"] += 1
        f.close()
        print >> sys.stderr, counts
        return counts

    def saveIds(self):
        if self.classIdFilename != None:
            print >> sys.stderr, "Saving class names to", self.classIdFilename
            self.classSet.write(self.classIdFilename)
        else:
            print >> sys.stderr, "Class names not saved"
        if self.featureIdFilename != None:
            print >> sys.stderr, "Saving feature names to", self.featureIdFilename
            self.featureSet.write(self.featureIdFilename)
        else:
            print >> sys.stderr, "Feature names not saved"

    def processCorpus(self, input, output, gold=None, append=False, allowNewIds=True, structureAnalyzer=None):
        # Create intermediate paths if needed
        if os.path.dirname(output) != "" and not os.path.exists(os.path.dirname(output)):
            os.makedirs(os.path.dirname(output))
        # Open output file
        openStyle = "wt"
        if append:
            #print "Appending examples"
            openStyle = "at"
        if output.endswith(".gz"):
            outfile = gzip.open(output, openStyle)
        else:
            outfile = open(output, openStyle)
        
        # Build examples
        self.exampleCount = 0
        if type(input) in types.StringTypes:
            self.elementCounts = self.getElementCounts(input)
            if self.elementCounts["sentences"] > 0:
#.........这里部分代码省略.........
开发者ID:DUT-LiuYang,项目名称:TEES,代码行数:103,代码来源:ExampleBuilder.py

示例2: OptionParser

# 需要导入模块: from Core.IdSet import IdSet [as 别名]
# 或者: from Core.IdSet.IdSet import write [as 别名]
            ExampleUtils.appendExamples(exampleCache, outFile)
            exampleCache = []
    ExampleUtils.appendExamples(exampleCache, outFile)
    outFile.close()
    print "Added", addCount, "polynomial features"

if __name__=="__main__":
    # Import Psyco if available
    try:
        import psyco
        psyco.full()
        print >> sys.stderr, "Found Psyco, using"
    except ImportError:
        print >> sys.stderr, "Psyco not installed"
        
    from optparse import OptionParser # For using command line options
    optparser = OptionParser()
    optparser.add_option("-i", "--ids", default=None, dest="ids", help="")
    optparser.add_option("-e", "--examples", default=None, dest="examples", help="")
    optparser.add_option("-j", "--idOutput", default=None, dest="idOutput", help="")
    optparser.add_option("-o", "--output", default=None, dest="output", help="")
    optparser.add_option("-w", "--weights", default=None, dest="weights", help="")
    optparser.add_option("-c", "--cutoff", type="float", default=10.0, dest="cutoff", help="")
    (options, args) = optparser.parse_args()

    #classIds = IdSet(filename="/usr/share/biotext/GeniaChallenge/extension-data/genia/edge-examples/genia-edge-ids.class_names")
    featureIds = IdSet(filename=options.ids)
    weightFeatures = readWeights(options.weights, options.cutoff)
    polynomizeExamples(options.examples, options.output, weightFeatures, featureIds)
    featureIds.write(options.idOutput)
开发者ID:jbjorne,项目名称:Tdevel,代码行数:32,代码来源:SVMMultiClassPolynomizeExamples.py

示例3: IdSet

# 需要导入模块: from Core.IdSet import IdSet [as 别名]
# 或者: from Core.IdSet.IdSet import write [as 别名]
       "Localization", 
       "Negative_regulation", 
       "Phosphorylation", 
       "Positive_regulation", 
       "Protein_catabolism", 
       "Regulation", 
       "Transcription"]

classSet = IdSet(filename=TRIGGER_IDS+".class_names")
for triggerClass in triggerClasses:
    makeOneClassExamples(TRIGGER_TRAIN_EXAMPLE_FILE, TRIGGER_TRAIN_EXAMPLE_FILE + "-" + triggerClass, triggerClass, classSet)
    makeOneClassExamples(TRIGGER_TEST_EXAMPLE_FILE, TRIGGER_TEST_EXAMPLE_FILE + "-" + triggerClass, triggerClass, classSet)
    d = {"neg":1, triggerClass:classSet.getId(triggerClass, False)}
    triggerClassIds = IdSet(idDict = d)
    TRIGGER_CLASS_IDS = "trigger-ids-"+triggerClass+".class_names"
    triggerClassIds.write(TRIGGER_CLASS_IDS)

    print >> sys.stderr, "Trigger models for parse", PARSE_TAG, "for class", triggerClass
    TRIGGER_CLASSIFIER_PARAMS="c:" + options.triggerParams
    if "local" not in options.csc:
        clear = False
        if "clear" in options.csc: clear = True
        if "louhi" in options.csc:
            c = CSCConnection(CSC_WORKDIR+"/trigger-models-"+triggerClass, "[email protected]", clear)
        else:
            c = CSCConnection(CSC_WORKDIR+"/trigger-models-"+triggerClass, "[email protected]", clear)
    else:
        c = None
    bestTriggerModel = optimize(CLASSIFIER, Ev, TRIGGER_TRAIN_EXAMPLE_FILE+"-"+triggerClass, TRIGGER_TEST_EXAMPLE_FILE+"-"+triggerClass,\
        TRIGGER_CLASS_IDS, TRIGGER_CLASSIFIER_PARAMS, "trigger-models-"+triggerClass, None, c, False)[1]
开发者ID:jbjorne,项目名称:Tdevel,代码行数:32,代码来源:TriggersWithMultipleClassifiers.py


注:本文中的Core.IdSet.IdSet.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。