| Trees | Indices | Help |
|
|---|
|
|
1 """A formalism that implements my 2nd-year PhD style of syntax: halfspan. 2 3 This formalism uses the 03/11 halfspan syntax, a development of the 4 old keyspan syntax, and a lambda-calculus semantics to go with it that 5 deals in tonal space coordinates. 6 7 This is the default (and, at the moment, only) formalism. 8 9 """ 10 """ 11 ============================== License ======================================== 12 Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 13 14 This file is part of The Jazz Parser. 15 16 The Jazz Parser is free software: you can redistribute it and/or modify 17 it under the terms of the GNU General Public License as published by 18 the Free Software Foundation, either version 3 of the License, or 19 (at your option) any later version. 20 21 The Jazz Parser is distributed in the hope that it will be useful, 22 but WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 GNU General Public License for more details. 25 26 You should have received a copy of the GNU General Public License 27 along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>. 28 29 ============================ End license ====================================== 30 31 """ 32 __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>" 33 34 from . import syntax, semantics, rules, domxml, evaluation, pcfg, songtools 35 from .semantics import distance 36 from jazzparser.formalisms import FormalismBase 37 from jazzparser.formalisms.base.semantics.timetools import TimeOutputTool 38 from jazzparser.utils.options import ModuleOption, choose_from_list41 rules = { 42 'application' : rules.ApplicationRule, 43 'composition' : rules.CompositionRule, 44 'development' : rules.DevelopmentRule, 45 'coordination' : rules.CoordinationRule, 46 'tonicrepetition' : rules.TonicRepetitionRule, 47 'cadencerepetition' : rules.CadenceRepetitionRule, 48 } 49 50 lexicon_builder = staticmethod(domxml.build_sign_from_node) 51 # We don't need to do anything to distinguish variables 52 distinguish_categories = staticmethod(lambda x,y: None) 53 unify = staticmethod(syntax.unify) 54 # This doesn't need to do anything for now 55 clean_results = staticmethod(lambda x:x) 56 57 shell_tools = [ 58 TimeOutputTool(), 59 songtools.LoadCorpusTool(), 60 songtools.ListSongsTool(), 61 songtools.PrintAnalysisTool(), 62 songtools.ResultSongTSEditDistanceTool(), 63 songtools.ResultSongDependencyRecoveryTool(), 64 songtools.RecogniseSongTool(), 65 songtools.SongSelfSimilarityTool(), 66 songtools.SongTreeTool(), 67 songtools.SongDependencyGraphTool(), 68 ] 69 70 output_options = [ 71 ModuleOption('tsformat', 72 choose_from_list(['coord', 'xycoord', 'roman','alpha']), 73 help_text="Tonal space output format", 74 default="coord", 75 usage="tsformat=X, where X is one of 'coord', 'xycoord', "\ 76 "'alpha' or 'roman'"), 77 ] 78 79 backoff_states_to_lf = staticmethod(semantics.backoff_states_to_lf) 80 semantics_to_coordinates = staticmethod(semantics.semantics_to_coordinates) 81 semantics_to_functions = staticmethod(semantics.semantics_to_functions) 82 semantics_to_keys = staticmethod(semantics.semantics_to_keys) 83 84 semantics_distance_metrics = [ 85 distance.TonalSpaceEditDistance, 86 distance.LargestCommonEmbeddedSubtrees, 87 distance.RandomDistance, 88 distance.DependencyGraphSize, 89 distance.OptimizedDependencyRecovery, 90 distance.DependencyRecovery, 91 ] 92 93 PcfgModel = pcfg.HalfspanPcfgModel 9416196 Sign = syntax.Sign 97 ComplexCategory = syntax.ComplexCategory 98 AtomicCategory = syntax.AtomicCategory 99 Slash = syntax.Slash 100 DummyCategory = syntax.DummyCategory 101 merge_equal_signs = staticmethod(syntax.merge_equal_signs) 102 103 # Unlike previous formalisms, we can't use the normal category 104 # structure abstraction, so we inject our own handling of 105 # half categories 106 pre_generalize_category = staticmethod(syntax.pre_generalize_category) 107 108 @classmethod129110 """ 111 For the sake of efficiency, override this and don't use 112 isinstance. 113 This gets called a LOT of times! 114 """ 115 return obj.ATOMIC == False116 117 @classmethod119 """ 120 For the sake of efficiency, override this and don't use 121 isinstance. 122 This gets called a LOT of times! 123 124 This works because the category classes in this formalism 125 all define ATOMIC, so we don't need to check the type. 126 127 """ 128 return obj.ATOMIC == True131 Semantics = semantics.Semantics 132 apply = staticmethod(semantics.apply) 133 compose = staticmethod(semantics.compose)134136 """ Formalism interface for the PcfgParser parser module. """ 137 # Function to generate the representation of a category to 138 # be used to index the model 139 category_representation = staticmethod(pcfg.model_category_repr) 140 # Mapping between the short names used for rules in annotated 141 # trees and the rule instantiations 142 rule_short_names = { 143 'compf' : ('composition', {'dir':'forward'}), 144 'compb' : ('composition', {'dir':'backward'}), 145 'appf' : ('application', {'dir':'forward'}), 146 'appb' : ('application', {'dir':'backward'}), 147 'cont' : ('development', {}), 148 'coord' : ('coordination', {}), 149 } 150 category_relative_chord = staticmethod(pcfg.category_relative_chord)151153 tonal_space_alignment_costs = staticmethod(evaluation.tonal_space_alignment_costs) 154 tonal_space_distance = staticmethod(evaluation.tonal_space_distance) 155 tonal_space_f_score = staticmethod(evaluation.tonal_space_f_score) 156 tonal_space_alignment_score = staticmethod(evaluation.tonal_space_alignment_score) 157 tonal_space_alignment = staticmethod(evaluation.tonal_space_alignment) 158 159 tonal_space_length = staticmethod(evaluation.tonal_space_length) 160 """ Number of points on the tonal space path represented by the semantics """
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Nov 26 16:05:02 2012 | http://epydoc.sourceforge.net |