def map_to_owl(json_data): for d in json_data: """mapping json data to ontology properties""" name = Preprocessor.toolname_underline(d['name']) # name = re.sub("[()-*,/]", " ", name).strip() executable = Preprocessor.normalize("saga_cmd ", d['command']['exec']) keywords = d['keywords'] toolClass = tool_class(keywords) if onto[name]: # if has the same name and executable if onto[name].executable == executable: onto[name].is_a.append(toolClass) continue else: name = name + '_' + keywords[0].replace(' ', '_') tool = toolClass(name, prefLabel=locstr(re.sub('^(Tool)[0-9: ]+', '', d['name']), lang='en')) # tool = toolClass(Preprocessor.space_2_underline(name), prefLabel=locstr(re.sub('^(Tool)[0-9: ]+', '', d['name']), lang='en')) tool.isToolOfSoftware.append(cyber.SAGA_GIS) tool.identifier = name tool.manualPageURL.append(d['manual_url']) # task handle_task(tool, name, d['name'], keywords, OWLUtils.join_list(d['description'])) tool.executable = executable tool.commandLine.append( Preprocessor.normalize("Usage: ", d['command']['cmd_line'])) tool.authors.append(OWLUtils.join_keywords(d['authors'])) for reference in d['references']: tool.references.append(reference) # keywords keywords.append(name.replace('_', ' ')) OWLUtils.link_to_domain_concept(tool, keywords) # applicaiton category OWLUtils.application_category(tool, [d['keywords'][0]], d['keywords'][1], d['keywords'][2:]) tool.description.append(OWLUtils.join_list(d['description'])) if d['parameters']: for item, itemValue in d['parameters'].items(): if item == 'inputs': handle_inout(tool, itemValue, 'input') elif item == 'outputs': handle_inout(tool, itemValue, 'output') elif item == 'options': for optionItem in itemValue: handle_options(tool, optionItem, onto)
def map_to_owl(json_data): """mapping json data to ontology properties""" tool_alsoes = [] for item in json_data: name = item['name'] if not name: continue if str(name).strip().find(' ') > 0: return # if str(name).strip().find(' ') > 0: continue # create or find tool class toolClass = tool_class(name) tool = toolClass(name, prefLabel=locstr(name, lang='en')) # tool = GrassTool(name, prefLabel=locstr(name, lang='en')) tool.isToolOfSoftware.append(cyber.GRASS_GIS) tool.identifier = name tool.manualPageURL.append(item['manual_url']) if 'addons' in item['manual_url']: tool.isAddon = True tool.description.append(locstr(item['description'], lang='en')) if item['source_code']: tool.sourceCodeURL.append(item['source_code']) tool.comment.append(item['notes']) tool.authors.append(OWLUtils.join_keywords(item['authors'])) tool.definition.append(item['definition']) keywords = item['keywords'] # tool.keywords.append(OWLUtils.join_keywords(item['keywords'])) # tool.subject.append(OWLUtils.join_keywords(item['keywords'])) # keywords and name # keywords.extend(name.split('.')[1:]) OWLUtils.link_to_domain_concept(tool, keywords) tool.commandLine.append(item['synopsis']) r = re.match('[a-z.]+ ', item['synopsis']) if r: tool.executable = str(r.group()).strip() see_also_items = {} for also in item['see_also']: if '.' not in also: continue see_also_items[tool] = [also] tool_alsoes.append(see_also_items) for parameter in item['parameters']: handle_parameters(tool, parameter, onto) handle_task(tool, name, name, item['keywords'], item['description']) handle_also(tool_alsoes) handle_applcation() topic_classes()