def __init__(self, peptidoform_string=None, verbose=None): self.peptidoform_string = None self.peptide_sequence = None self.residue_modifications = {} self.terminal_modifications = {} self.unlocalized_mass_modifications = {} self.neutral_mass = None self.response = Response() self.is_valid = False if len(ontologies) == 0: #print("Loading ontologies...", end='', flush=True) #ontologies['UNIMOD'] = Ontology(filename='G:/Repositories/SVN/proteomics/var/CV/unimod.obo') #ontologies['PSI-MOD'] = Ontology(filename='G:/Repositories/SVN/proteomics/var/CV/PSI-MOD.obo') ontologies['UNIMOD'] = Ontology( filename= '/net/dblocal/wwwspecial/proteomecentral/extern/CVs/unimod.obo' ) ontologies['PSI-MOD'] = Ontology( filename= '/net/dblocal/wwwspecial/proteomecentral/extern/CVs/PSI-MOD.obo' ) #print(" done.") if peptidoform_string: self.parse(peptidoform_string, verbose=None)
def parse(oboFile, typedefs): """ Parses an OBO (ontology file) creating a correspoinding Ontology object composed of Term objects that relate to the terms found in the ontology file. """ ontology = Ontology() ## Use groupby to group the lines of our file into chunks of text, some ## stanzas, some typedefs, and other metadata to be processed with open(oboFile) as f: for (key, group) in groupby(f, is_data): if key: header = group.next().rstrip('\n') if header.find('[Typedef]') != -1: dataDict = get_data_as_dict(group) ontology.add_typedef(dataDict['name']) elif header.find('[Term]') != -1: dataDict = get_data_as_dict(group, typedefs) ontology.add_term(build_term(dataDict)) else: # We are dealing with ontology metadata that should be # captured in our ontology object. ontology.metadata.append(header) ontology.metadata.extend([x.strip() for x in group]) return ontology
def _run(self): """ Runs the inferencing pipeline. """ #self._retrieveAndCheckFilePaths() if self.srcpath != '': sourceont = Ontology(self.srcpath) else: sourceont = Ontology(JavaSystem.in) logger.info('Running reasoner and adding inferred axioms...') inf_types = self.config.getInferenceTypeStrs() annotate_inferred = self.config.getAnnotateInferred() preprocess_inverses = self.config.getPreprocessInverses() iaa = InferredAxiomAdder(sourceont, self.config.getReasonerStr()) if self.config.getExcludedTypesFile() != '': iaa.loadExcludedTypes(self.config.getExcludedTypesFile()) iaa.addInferredAxioms( inf_types, annotate_inferred, preprocess_inverses ) # Write the ontology to the output file or stdout. format_str = self.config.getOutputFormat() if self.outpath != '': logger.info('Writing compiled ontology to ' + self.outpath + '...') sourceont.saveOntology(self.outpath, format_str) else: sourceont.printOntology(format_str)
def psims_example(): ontology = Ontology(filename='psi-ms.obo', verbose=1) ontology.show() print("============================") term = ontology.terms["MS:1002286"] term.show() print("============================") name = 'QIT' print(f"Searching for '{name}'") if name in ontology.names: curies = ontology.names[name] for curie in curies: term = ontology.terms[curie] term.show() print("============================") name = 'bit' result_list = ontology.fuzzy_search(search_string=name) for item in result_list: print(item) print("============================") name = 'bit' result_list = ontology.fuzzy_search(search_string=name, children_of="MS:1000031") for item in result_list: print(item)
def _run(self): """ Runs the build process to produce the ontology documentation. """ fileoutinfos = self.getOutputFileInfos() # Create the destination directory, if needed. We only need to check # this for in-source builds, since the BuildDirTarget dependency will # take care of this for out-of-source builds. if self.config.getDoInSourceBuilds(): destdir = os.path.dirname(fileoutinfos[0].destpath) if not (os.path.isdir(destdir)): self._makeDirs(destdir) logger.info('Creating ontology documentation files...') ont = Ontology(self.mobt_reasoned.getOutputFilePath()) # Create the documentation files. for foutinfo in fileoutinfos: # If the format is HTML, make sure the supporting CSS and # Javascript files are present. if foutinfo.formatstr == 'html': destdir = os.path.dirname(foutinfo.destpath) self._checkWebFiles(['documentation_styles.css', 'navtree.js'], destdir) writer = getDocumentationWriter(foutinfo.formatstr) documenter = Documenter(ont, writer) with open(self.config.getDocSpecificationFile()) as docspec: with open(foutinfo.destpath, 'w') as fout: documenter.document(docspec, fout)
def init(_boardname=None): global player, game name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer1' #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer2' #NON #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer3' #name = _boardname if _boardname is not None else '10x10' #name = _boardname if _boardname is not None else 'Lab_15x15' #NON #name = _boardname if _boardname is not None else 'map' #NON #name = _boardname if _boardname is not None else 'map2' #NON #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_6x6' #NON #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_bomberman' #YES #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_impossible' #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_incroyable' #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_labyrinthe2' #name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer_labyrinthe3' #NON #name = _boardname if _boardname is not None else 'thirst' #NON game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 20 # frames per second game.mainiteration() game.mask.allow_overlaping_players = True
def main(): if (sys.argv[-1] == '--collect'): url_pois = 'https://pt.foursquare.com/explore?mode=url&ne=-29.358988%2C-50.837817&q=Sele%C3%A7%C3%B5es%20principais&sw=-29.41889%2C-50.887942' url_city = 'http://www.dataviva.info/pt/location/5rs020102' e = Extraction(url_pois, url_city) e.poi_data_extraction() e.city_data_extraction() # Gera relatório do dataset file = 'foursquare_data.csv' df = pd.read_csv(file, parse_dates=True, encoding='UTF-8') profile = pandas_profiling.ProfileReport(df) profile.to_file(outputfile='dataset_report.html') P = Process(file) df = P.method() df_report = pd.read_csv('preprocessed.csv', parse_dates=True, encoding='UTF-8') profile = pandas_profiling.ProfileReport(df_report) profile.to_file(outputfile='preprocessed_dataset_report.html') R = Recommendation(df) R.pattern_recommendation() R.new_recommendation() R.compare() # R.test_rec() ont = Ontology() ont.write_owl()
def po_example(): ontology = Ontology(filename='plant-ontology.obo', verbose=1) ontology.show() print("============================") name = 'xyl' result_list = ontology.fuzzy_search(search_string=name) for item in result_list: print(item)
def init(_boardname=None): global player, game name = _boardname if _boardname is not None else 'pathfindingWorld_multiPlayer' game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 5 # frames per second game.mainiteration()
def init_game(_boardname=None): global player, game name = _boardname if _boardname is not None else 'kolkata_6_10' game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 20 # frames per second game.mainiteration() game.mask.allow_overlaping_players = True
def init(_boardname=None): global player,game # pathfindingWorld_MultiPlayer4 name = _boardname if _boardname is not None else 'tictactoe' game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 2 # frames per second game.mainiteration() game.mask.allow_overlaping_players = True
def init(_boardname=None): global player, game, tailleV, tailleH name = _boardname if _boardname is not None else 'pathfindingWorld3' game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 5 # frames per second game.mainiteration() player = game.player tailleV = game.spriteBuilder.rowsize tailleH = game.spriteBuilder.colsize
def _run(self): """ Reads the source ontologies and looks for the search terms. """ ef = EntityFinder() for search_ont in self.search_onts: logger.info('Reading source ontology {0}...'.format(search_ont)) ontology = Ontology(search_ont) logger.info('Processing ontology entities...') ef.addOntologyEntities(ontology) if self.tfpath != '': termsin = open(self.tfpath) else: termsin = sys.stdin if self.outpath != '': logger.info('Writing search results to ' + self.outpath + '...') fout = open(self.outpath, 'w') else: fout = sys.stdout writer = csv.DictWriter(fout, fieldnames=[ 'Search term', 'Matching entity', 'Label(s)', 'Annotation', 'Value', 'Match type', 'Definition(s)' ]) writer.writeheader() row = {} for searchterm in termsin: searchterm = searchterm.strip() results = ef.findEntities(searchterm) for result in results: entity = result[0] row['Search term'] = searchterm row['Matching entity'] = str(entity.getIRI()) row['Label(s)'] = ','.join(entity.getLabels()) row['Annotation'] = result[1] row['Value'] = result[2] row['Definition(s)'] = ','.join(entity.getDefinitions()) if result[3] == MATCH_FULL: row['Match type'] = 'Full' else: row['Match type'] = 'Partial' writer.writerow(row)
def _run(self): """ Runs the build process to produce a new ontology release. """ # We don't need to run generateBuildInfo() here because the base class # ensures that _isBuildRequired() will always be called prior to this # method, so generateBuildInfo() will have already been run. # Create the main release directory, if needed. if not (os.path.isdir(self.release_dir)): self._makeDirs(self.release_dir) # Get the path to the released imports modules directory and create it, # if needed. if len(self.imports_fileinfos) > 0: dirpath = os.path.dirname(self.imports_fileinfos[0].destpath) if not (os.path.exists(dirpath)): self._makeDirs(dirpath) # Create the release import module files. logger.info('Creating release import modules...') for fileinfo in self.imports_fileinfos: ont = Ontology(fileinfo.sourcepath) ont.setOntologyID(fileinfo.destIRI, fileinfo.versionIRI) ont.saveOntology(fileinfo.destpath) # Create the release ontology files. logger.info('Creating release ontology files...') for fileinfo in self.ont_fileinfos: ont = Ontology(fileinfo.sourcepath) ont.setOntologyID(fileinfo.destIRI, fileinfo.versionIRI) # Update the IRIs of any released import modules that are # explicitly imported by the ontology. for ifinfo in self.imports_fileinfos: if ont.hasImport(ifinfo.oldIRI): ont.updateImportIRI(ifinfo.oldIRI, ifinfo.versionIRI) ont.saveOntology(fileinfo.destpath, self.config.getOutputFormat())
def init(_boardname=None): global player, game, nbreCol, nbreLig # pathfindingWorld_MultiPlayer4 name = _boardname if _boardname is not None else 'pathfindingWorld_MultiPlayer5' game = Game('Cartes/' + name + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = 5 # frames per second game.mainiteration() game.mask.allow_overlaping_players = True nbreCol = game.spriteBuilder.colsize - 1 nbreLig = game.spriteBuilder.rowsize - 1 player = game.player
def _run(self): """ Runs the build process and produces a new, modified version of the main OWL ontology file. """ timer = BasicTimer() timer.start() self._retrieveAndCheckFilePaths() mainont = Ontology(self.obt.getOutputFilePath()) if self.mergeimports: # Merge the axioms from each imported ontology directly into this # ontology (that is, do not use import statements). logger.info( 'Merging all imported ontologies into the main ontology...') for importIRI in mainont.getImports(): mainont.mergeOntology(importIRI, self.config.getAnnotateMerged()) if self.prereason: logger.info('Running reasoner and adding inferred axioms...') inf_types = self.config.getInferenceTypeStrs() annotate_inferred = self.config.getAnnotateInferred() preprocess_inverses = self.config.getPreprocessInverses() iaa = InferredAxiomAdder(mainont, self.config.getReasonerStr()) if self.config.getExcludedTypesFile() != '': iaa.loadExcludedTypes(self.config.getExcludedTypesFile()) iaa.addInferredAxioms(inf_types, annotate_inferred, preprocess_inverses) fileoutpath = self.getOutputFilePath() # Set the ontology IRI. ontIRI = self.config.generateDevIRI(fileoutpath) mainont.setOntologyID(ontIRI) # Write the ontology to the output file. logger.info('Writing compiled ontology to ' + fileoutpath + '...') mainont.saveOntology(fileoutpath, self.config.getOutputFormat()) if self.mergeimports and self.prereason: msgtxt = 'Merged and reasoned ' elif self.mergeimports: msgtxt = 'Merged ' else: msgtxt = 'Reasoned ' logger.info((msgtxt + 'ontology build completed in {0} s.\n').format( timer.stop()))
def extractModule(self, mod_iri): """ Extracts a module that is a subset of the entities in the source ontology. The result is returned as an Ontology object. mod_iri: The IRI for the extracted ontology module. Can be either an IRI object or a string containing a relative IRI, prefix IRI, or full IRI. """ modont = Ontology(self.ontology.ontman.createOntology()) modont.setOntologyID(mod_iri) # Do the syntactic locality extraction. Only do the extraction if the # signature set is non-empty. The OWL API module extractor will # produce a non-empty module even for an empty signature set. if len(self.signatures[methods.LOCALITY]) > 0: slme = SyntacticLocalityModuleExtractor(self.ontology.ontman, self.owlont, ModuleType.STAR) mod_axioms = slme.extract(self.signatures[methods.LOCALITY]) for axiom in mod_axioms: modont.addEntityAxiom(axiom) # Do all single-entity extractions. self._extractSingleEntities(self.signatures[methods.SINGLE], modont) # Add all saved axioms. for axiom in self.saved_axioms: modont.addEntityAxiom(axiom) # Remove any entities that should be excluded from the final module. for ent in self.excluded_entities: modont.removeEntity(ent, remove_annotations=True) # Add an annotation for the source of the module. sourceIRI = None ontid = self.owlont.getOntologyID() if ontid.getVersionIRI().isPresent(): sourceIRI = ontid.getVersionIRI().get() elif ontid.getOntologyIRI().isPresent(): sourceIRI = ontid.getOntologyIRI().get() if sourceIRI is not None: modont.setOntologySource(sourceIRI) return modont
def _run(self): """ Runs the build process and produces a compiled OWL ontology file. """ # Get the imports modules IRIs from the imports build target. importinfos = self.ibt.getImportsInfo() self._retrieveAndCheckFilePaths() baseont = Ontology(self.base_ont_path) # Add an import declaration for each import module. for importinfo in importinfos: baseont.addImport(importinfo.iristr, True) # Write the base ontology to the output file. fileoutpath = self.getOutputFilePath() logger.info('Writing updated base ontology to ' + fileoutpath + '...') baseont.saveOntology(fileoutpath)
def __init__(self, boardNumber=1, boardName=None, fps=5, iterations=100): """ boardNumber : identifiant de la carte de jeu à utiliser. fps : nombre de cadres par seconde. iterations : nombre maximal d'itérations. """ global game if boardName is None: game = Game( 'Cartes/pathfindingWorld_MultiPlayer' + str(boardNumber) + '.json', SpriteBuilder) else: game = Game('Cartes/' + str(boardName) + '.json', SpriteBuilder) game.O = Ontology(True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') game.populate_sprite_names(game.O) game.fps = fps # frames per second game.mainiteration() game.mask.allow_overlaping_players = False self.iterations = iterations
def parse_tree(tree_filename): """Build tree given json file. Args: tree_filename: A string, path of json file describing tree from leaf to root Returns: tree_leaf2root: leaf to root dict sumrule: sumrule dict. """ with open(tree_filename, 'rb') as fp: tree_str = json.loads(fp.read()) tree_leaf2root = {} for k, v in tree_str.items(): if v is not None: tree_leaf2root[int(k)] = int(v) else: tree_leaf2root[int(k)] = None tree = Ontology(tree_leaf2root) sumrule = tree.sumrules return tree_leaf2root, sumrule
def __init__(self, _boardname=None, swap=False, affiche=True): self.game = Game() name = _boardname if _boardname is not None else 'at2' self.game = Game('Cartes/' + name + '.json', SpriteBuilder) self.game.O = Ontology( True, 'SpriteSheet-32x32/tiny_spritesheet_ontology.csv') self.game.populate_sprite_names(self.game.O) self.game.fps = 2 # frames per second self.affiche = affiche if affiche: self.game.mainiteration() self.game.mask.allow_overlaping_players = True # player = game.player # on localise tous les états initiaux (loc du joueur) self.initStates = [o.get_rowcol() for o in self.game.layers['joueur']] print("Init states:", self.initStates) # on localise tous les objets ramassables self.goalStates = [ o.get_rowcol() for o in self.game.layers['ramassable'] ] print("Goal states:", self.goalStates) # on localise tous les murs self.wallStates = [ w.get_rowcol() for w in self.game.layers['obstacle'] ] # print ("Wall states:", self.wallStates) self.nbIteration = 0 if swap: self.goalStates[0], self.goalStates[1] = self.goalStates[ 1], self.goalStates[0] self.players = [o for o in self.game.layers['joueur']]
def __init__(self, base_ont_path): # Load the base ontology. self.ontology = Ontology(base_ont_path) # Get a PrefixDocumentFormat/PrefixManager instance so that we can # generate prefix IRIs for label expansions in text entity definitions. owlont = self.ontology.getOWLOntology() ontman = self.ontology.getOntologyManager() self.prefix_df = ontman.getOntologyFormat(owlont).asPrefixOWLOntologyFormat() # A list (used as a stack) for caching information in _TableRow objects # and their associated ontology entity objects. Each list entry is # stored as a tuple, (ontology entity instance, _TableRow instance). self.entity_trows = [] # Create a delimited string parser for parsing multiple values out of # input fields. self.dsparser = DelimStrParser(delimchars=';', quotechars='"') # Create a delimited string parser for parsing the components of # strings with whitespace-separated components, such as individual # property assertions (facts). self.ws_dsparser = DelimStrParser(delimchars=' \t', quotechars='"\'')
def _run(self): """ Checks for entailment errors in the main ontology. """ mainont = Ontology(self.obt.getOutputFilePath()) timer = BasicTimer() logger.info('Checking for entailment errors...') timer.start() entcheck_res = mainont.checkEntailmentErrors( self.config.getReasonerStr()) logger.info('Logical error check completed in {0} s'.format( timer.stop())) if not (entcheck_res['is_consistent']): logger.info( '\nERROR: The ontology is inconsistent (that is, it has no ' 'models). This is often caused by the presence of an ' 'individual (that is, a class instance) that is explicitly or ' 'implicitly a member of two disjoint classes. It might also ' 'indicate an underlying modeling error. Regardless, it is a ' 'serious problem because an inconsistent ontology cannot be ' 'used for logical inference.\n') else: class_list = entcheck_res['unsatisfiable_classes'] if len(class_list) > 0: iri_strs = [ent.getIRI().toString() for ent in class_list] classes_str = '<' + '>\n<'.join(iri_strs) + '>' logger.info( '\nERROR: The ontology is consistent but incoherent ' 'because it contains one or more unsatisfiable classes. ' 'This usually indicates a modeling error. The following ' 'classes are unsatisfiable:\n' + classes_str + '\n') else: logger.info('\nThe ontology is consistent and coherent. No ' 'entailment problems were found.\n')
#!/usr/bin/python # -*- coding: utf-8 -*- from ontology import Ontology import time start_time = time.time() if __name__ == '__main__': myOntology = Ontology() myOntology.automatic_filling(do_test=True) print("--- %s seconds ---" % (time.time() - start_time))
if __name__ == "__main__": data_dir = "json" tags = [ "Acoustic guitar", "Bass guitar", "Strum", "Piano", "Independent music", "Wedding music", "Scary music", "Firecracker", "Drip", ] ontology = Ontology(data_dir) """ # Calculate maximum tree distance between tags print("Calculate maximum tree distance between tags") max_dist = get_max_tree_distance(ontology, tags, debug=False) print("Maximum tree distance: ", max_dist, end="\n\n") # Convert distances to scores with max_dist print("Convert distances to scores with max_dist") distances = np.array([0, 0, 1, 2, 1, 0, 5, 4, 8, 9]) print("Distances: ", distances) scores = dist_to_score(ontology, distances, max_dist=max_dist, debug=True) print("Scores: ", scores, end="\n\n") # Convert distances to scores with tags print("Convert distances to scores with tags")
def all_url_test(): l = classgenerator.Library() l2 = classgenerator.Library() l2.base_path = ["gentest", "lib", "ontologies"] #print ("test of getting global data") g = test_global_data_files.get_global_data() #print (g) predicates = Counter() subjects = Counter() predicate_types = Counter() predicate_types2 = Counter() objects = Counter() rebind(g) for x in g: p = x[1] s = x[0] o = x[2] predicates[p] += 1 subjects[s] += 1 objects[o] += 1 print "predicates" seen = {} libs = {} for (p, v) in predicates.most_common(4230): if 'openlinksw.com' in p: continue if 'cc.rww.io' in p: continue p2 = g.namespace_manager.qname(p) (ns, term) = p2.split(':') m = g.namespace_manager.store.namespace(ns) # skip if str(m) == 'http://www.w3.org/1999/xhtml/vocab#': continue if ns not in seen: #print "NS",ns, m seen[ns] = 1 if 'ns' in ns: print "g.namespace_manager.bind(\"{prefix}\",\"{url}\",True) ".format( prefix=ns, url=m) #pass path = l.get_module(ns, m) #print ns, m, path if path: importl = l.get_import_path(path) prefix = l.get_import_path(ns) #l.createpath(path) #l.create_module(path,prefix,url=m) #print "import {module} as {prefix}".format(module=importl,prefix=ns) replace = { 'http://purl.org/dc/dcam/': 'https://raw.githubusercontent.com/dcmi/vocabtool/master/build/dcam.rdf' } if str(m) in replace: o = replace[str(m)] #print "replacing " ,m,"with", o m = o _format = 'guess' turtles = [ 'http://www.w3.org/ns/ldp#', 'http://usefulinc.com/ns/doap#', ] if str(m) in turtles: _format = 'turtle' xmls = [ 'http://xmlns.com/foaf/0.1/', 'http://www.w3.org/ns/auth/cert#', 'http://www.w3.org/ns/auth/acl#', 'http://www.w3.org/2000/10/swap/pim/doc#', 'http://www.w3.org/2003/06/sw-vocab-status/ns#', ] if str(m) in xmls: _format = 'xml' o = Ontology(url=m, prefix=prefix, _format=_format) o.set_path(path) #print "prefix", prefix, m libs[prefix] = o ## now revisit the graph and link it #pprint.pprint(libs) for p in libs: o = libs[p] prefix = o.prefix #print "Lib", p, o.path og = o.fetch(g.namespace_manager) rebind(og) od = o.extract_graph(og, l, libs) ours = od[0] others = od[2] prefixs = od[2] code = [] importcode = [] # create members used_prefixes = {} for x in ours: if 'http' in x: pass else: types = [] # lets try and create a class attrs = ours[x] for y in attrs: p = y[0] s = y[1] p1 = resolve(p) s1 = resolve(s) if p1 == 'rdf.type': if s1 == 'owl.Restriction': pass else: types.append(s1) ## append to used types #print "check prefix for import",s,s1 used_prefixes[s[0]] = 1 #print "\t","pred",p1,s1 if len(types) > 0: caml = convert2(x) short = convert(x) if caml.startswith('Ub'): pass else: classcode = ast.parse( "class {_class}({base}):\n term=\"{name}\"\n". format(_class=caml, name=x, base=",".join(types))) used_prefixes[prefix] = 1 alias_code = ast.parse("{alias} = {_class}()\n".format( prefix=prefix, alias=short, _class=caml)) code.append(classcode) code.append(alias_code) ##### create prefixes for x in prefixs: m = prefixs[x] if x not in used_prefixes: continue # remove unused prefixes if x == o.prefix: continue import_module = Module(body=[ ImportFrom(module=m.module_name(), names=[alias(name='ontology', asname=x)], level=0) ]) #code = "from {module} import ontology as {alias}".format(module=m.module_name(), alias=x) # x = Import(names=[alias( # name=m.module_name(), # asname=None)]), #print(astunparse.dump(ast.parse(code))) importcode.append(import_module) ### if True: npath = "gentest/" + o.path #path = l.get_module(ns,m) #print ns, m, path importl = l.get_import_path(npath) #prefix = l.get_import_path(ns) l.createpath(npath) print "npath", npath #print code l.create_module(npath, o.prefix, url=o.base, members=code, imports=importcode)
from typing import List from ontology import Ontology from summarizers import TextRankSummarizer, LeskSummarizer, OntologySummarizer, BlendedSummarizer from text_utils import read_docs, Document ontology = Ontology('ontologies/sport.json') doc_dir = 'BBC News Summary/News Articles/sport' doc_dir_summary = 'BBC News Summary/Summaries/sport' docs: List[Document] = read_docs(doc_dir, doc_dir_summary, n_docs=-1) print('Read {} docs...'.format(len(docs))) ontology_summarizer = OntologySummarizer(docs, ontology) ontology_summarizer.summarize_docs() textrank_summarizer = TextRankSummarizer(docs) textrank_summarizer.summarize_docs() textrank_summarizer.performance() lesk_summarizer = LeskSummarizer(docs) lesk_summarizer.summarize_docs() lesk_summarizer.performance() # blended_summarizer = BlendedSummarizer( docs, summarizers=[textrank_summarizer, lesk_summarizer, ontology_summarizer]) blended_summarizer.performance()
#!/usr/bin/python # -*- coding: utf-8 -*- from ontology import Ontology import json if __name__ == '__main__': ontology = Ontology() while True: string_input = raw_input("\n\n\n입력 (EXIT) = ") if string_input == "EXIT": break try: json_input = json.loads(string_input) except ValueError: print "\n\n\nNot Valid JSON Format - ", string_input else: print "Sentence -", string_input json_output = ontology.semantic_tagging(json_input) if json_output: pass else: print "\n\n\nNot Valid JSON Format - ", string_input
from flask_cors import CORS import argparse __dirname = os.path.dirname(os.path.realpath(__file__)) parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", type=int, default=3279, help="Port") program_args = parser.parse_args() app = Flask("omega-topology-MIontology") CORS(app) ONTOLOGY_FILE = __dirname + "/../mi.owl" ROOT_ID = "MI:0001" onto = Ontology(ONTOLOGY_FILE) def constructTree(root_id, seeds): tree = onto.constructTreeFromRoot(root_id) pruned = tree.prune(seeds).toDict() return pruned root_tree = onto.constructTreeFromRoot(ROOT_ID) def getLabelOf(id): node = root_tree.findInTree(id)
def buildModule(self, ontologyIRI, termsfile_path): """ Builds an import module from a single external ontology and an input file containing a set of terms to import. The import module will be saved as an OWL file with a name generated by appending self.mod_suffix to the base of the source ontology file name. ontologyIRI (string): The IRI of the source ontology. termsfile_path: The input file containing the terms to import. """ # Verify that the terms file exists. if not (os.path.isfile(termsfile_path)): raise RuntimeError('Could not find the input terms file "' + termsfile_path + '".') # Check the output directories. self._checkOutputDirs() # Extract the name of the source ontology file from the IRI and # generate the path to it on the local filesystem. ontfile = os.path.basename(ontologyIRI) ontfile = os.path.join(self.ontcachedir, ontfile) # Verify that the source ontology file exists; if not, download it. if not (os.path.isfile(ontfile)): opener = URLOpenerWithErrorHandling() try: self.sourceOntologyIRI = ontologyIRI opener.retrieve(ontologyIRI, ontfile, self._updateDownloadProgress) except (IOError, HTTPError) as err: raise RuntimeError( 'Unable to download the external ontology at "' + ontologyIRI + '": ' + unicode(err)) # Add an IRI mapping so that requests to load the imported ontology # will retrieve it from the local file. doc_iristr = urlparse.urljoin('file://localhost', urllib.pathname2url(ontfile)) oom_manager.addNewIRIMapping(IRI.create(ontologyIRI), IRI.create(doc_iristr)) ontopilot.logger.info('Loading source ontology from file ' + ontfile + '.') sourceont = Ontology(ontfile) mod_ext = ModuleExtractor(sourceont) excluded_ents = [] with TableReaderFactory(termsfile_path) as reader: # Read the terms to import from each table in the input file, add # each term to the signature set for module extraction, and add the # descendants of each term, if desired. for table in reader: table.setRequiredColumns(self.REQUIRED_COLS) table.setOptionalColumns(self.OPTIONAL_COLS) table.setDefaultValues(self.DEFAULT_COL_VALS) for row in table: if row['Ignore'].lower() in TRUE_STRS: continue idstr = row['ID'] ontopilot.logger.info('Processing entity "' + idstr + '".') try: rel_types = rel_axiom_types.getAxiomTypesFromStr( row['Related entities']) if row['Exclude'].lower() in TRUE_STRS: mod_ext.excludeEntity(idstr, rel_types) else: method = me_methods.getMethodFromStr(row['Method']) mod_ext.addEntity(idstr, method, rel_types) except RuntimeError as err: raise ImportModSpecError(unicode(err), row) if mod_ext.getSignatureSize() == 0: ontopilot.logger.warning( 'No terms to import were found in the terms file ' '{0}.'.format(termsfile_path)) module = mod_ext.extractModule(self.getModuleIRIStr(ontologyIRI)) module.saveOntology(self.getModulePath(ontologyIRI))