From: Lars H. <lh...@us...> - 2005-03-06 17:10:43
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21112/utils Added Files: terminology.py tm4j2tmapi.py Log Message: TM4J -> TMAPI translator --- NEW FILE: tm4j2tmapi.py --- #!/usr/bin/env python """ The converter. Only a quick hack, just string replacements. """ import sys, os from stat import * from terminology import transtable, critical def convertFile(tm4jFileName, tmapiFileName): """ Converts a TM4J file into a file with TMAPI terms @param tm4jFileName: The TM4J file to convert. @param tmapiFileName: The file that should be used for output. May be identical to TM4J file. """ f = open(tm4jFileName, 'r') lines = f.readlines() f.close() f = open(tmapiFileName, 'w') cnt = 1 log.write('File: %s\n' % tm4jFileName) flog.write('File: %s\n' % tm4jFileName) for line in lines: for term in critical.keys(): # If a 'critical' term was found report it in log if line.find(term) != -1: log.write(' line: %s\n' % cnt) log.write(' %s\n' % term) log.write(' %s\n' % critical[term]) for tm4jTerm, tmapiTerm in transtable.iteritems(): newLine = line.replace(tm4jTerm, tmapiTerm) if newLine != line: flog.write(' line: %s\n' % cnt) flog.write(' %s -> %s\n' % (tm4jTerm, tmapiTerm)) flog.write(' %s' % line) flog.write(' -> %s' % newLine) flog.write('\n') line = newLine cnt += 1 f.write(line) log.write('\n') flog.write('\n') flog.write('\n') f.close() def directoryWalk(arg, dirname, names): for name in names: fn = os.path.join(dirname, name) if (os.path.splitext(fn)[1] == '.java'): mode = os.stat(fn)[ST_MODE] if (not S_ISDIR(mode)): # Caution: TM4J file == TMAPI file! convertFile(fn, fn) try: dirname = sys.argv[1] except IndexError: print """ Usage: python tm4j2tmapi.py <directory> <directory>: The directory name where all .java files should converted to TMAPI terms. Caution: - The files in the specified directory will be overridden! - A logcritical.txt and a linechanges.txt file will be written. If files exist they will be overridden!""" sys.exit(1) flog = open('linechanges.txt', 'w') log = open('logcritical.txt', 'w') os.path.walk(dirname, directoryWalk, None) flog.close() log.close() --- NEW FILE: terminology.py --- """ Translation table TM4J term -> TMAPI term. Only the 'transtable' and the 'critical' dicts are used by the converter. The critical dict contains terms that are either not translatable or need some further work. """ # <TM4J Term>:<TMAPI Term> paths = { 'org.tm4j.topicmap.index.basic':'org.tmapi.index.core', 'org.tm4j.topicmap':'org.tmapi.core', 'org.tm4j.tologx':'org.tmapiutils.query.tolog', # org.tm4j.topicmap.index.basic # -> org.tmapi.core.index.basic # -> org.tmapi.index.core 'core.index.basic':'index.core', } classes = { 'BaseNameDataIndex':'TopicNamesIndex', 'TopicNameDataIndex':'TopicNamesIndex', # if BaseName -> TopicName replacement 'OccurrenceTypesIndex':'OccurrencesIndex', 'OccurrenceDataIndex':'OccurrencesIndex', 'VariantDataIndex':'VariantsIndex', 'OccurrenceLocatorIndex':'OccurrencesIndex', 'VariantLocatorIndex':'VariantsIndex', 'MemberTypesIndex':'AssociationRolesIndex', 'AssociationRoleTypesIndex':'AssociationRolesIndex', # if Member -> AssociationRole replacement 'TopicTypesIndex':'TopicsIndex', # AssociationRole 'Member':'AssociationRole', # TopicName 'BaseName':'TopicName', 'VariantName':'Variant' } # Methods for org.tmapi.core methods_core = { # Locator 'getAddress()':'getReference()', # TopicMapObject 'getId()':'getObjectId()', # ScopingTopic 'addTheme(':'.addScopingTopic(', 'removeTheme(':'removeScopingTopic(', # TopicMap 'getTopicsIterator()':'getTopics().iterator()', 'getAssociationsIterator()':'getAssociations().iterator()', 'getTopicById(':'getObjectById(', # Topic 'getNames()':'getTopicNames()', 'getSubject()':'getSubjectLocators()', 'setSubject(':'addSubjectLocator(', 'getSubjectIndicators()':'getSubjectIdentifiers()', 'addSubjectIndicator(':'addSubjectIdentifier(', 'removeSubjectIndicator(':'removeSubjectIdentifier(', # Association 'getMembers()':'getAssociationRoles()', # AssociationRole 'getRoleSpec()':'getType()', 'setRoleSpec(':'setType(', # Occurrence, Variant 'getDataLocator()':'getResource()', 'setDataLocator(':'setResource(', # TopicName, Occurrence, Variant 'getData()':'getValue()', 'setData(':'setValue(' } # Methods for org.tmapi.index / org.tmapi.index.core methods_index = { # ScopedObjectsIndex 'getThemes()':'getScopingTopics()', # TopicsIndex 'getTopicsOfType(':'getTopicsByType(', 'getTopicsOfTypes(':'getTopicsByTypes(', # AssociationsIndex 'getAssociationsOfType(':'getAssociationsByType(', # AssociationRolesIndex 'getMemberTypes()':'getAssociationRoleTypes()', 'getMembersOfType(':'getAssociationRolesByType(', # OccurrencesIndex 'getOccurrencesOfType(':'getOccurrencesByType(', 'getOccurrencesOfLocator(':'getOccurrencesByResource(', 'getOccurrencesByData(':'getOccurrencesByValue(', # TopicNamesIndex 'getBaseNamesByData(':'getTopicNamesByValue(', 'getTopicNamesByData(':'getTopicNamesByValue(', # if BaseName -> TopicName replacement # VariantsIndex 'getVariantsOfLocator(':'getVariantsByResource(', 'getVariantsByData(':'getVariantsByValue(' } # <TM4J Term>:<Hint for an human> critical = { 'DataObject':'DataObject has no equivalent in TMAPI (either an Occurrence or a Variant)', 'VariantContainer':'VariantContainer does not exist in TMAPI (a TopicName is a VariantContainer)', 'TopicMapProvider':'Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem', 'getParent()':'Cannot resolve getParent', 'TopicMapUtils':'Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!)', 'IDGeneratorFactory':'Has become org.tmapi.core.utils.IDGeneratorFactory', # Topic 'getSubject()':'Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something', 'setSubject(':'If locator is null, use removeSubjectLocator', # TopicMap 'getIndexManager()':'Should become getHelperObject(IndexInterface.class)', 'getTopicBySubject(':'TopicMap.getTopicBySubject -> TopicsIndex.getTopicBySubjectLocator', 'getTopicBySubjectIndicator(':'TopicMap.getTopicBySubjectIndicator -> TopicsIndex.getTopicBySubjectIdentifier', 'getObjectBySourceLocator(':'TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator', 'getTopicById':'Has become "getObjectById". Typecast necessary!', # ScopedObjectsIndex 'getScopedObjects(':'Could be getScopedObjectsByScopingTopic or ..ByScopingTopics', # AssociationRole 'getPlayers()':'AssociationRole can have only one player', 'setPlayers(':'AssociationRole can have only one player', # Factory methods 'createName':'Must become "createTopicName"', 'createMember':'Must become "createAssociationRole"' } # The dict that is used by the converter transtable = {} transtable.update(paths) transtable.update(classes) transtable.update(methods_core) transtable.update(methods_index) |