Beispiel #1
0
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)
Beispiel #2
0
def map_to_owl(json_data):
	for d in json_data:
		"""mapping json data to ontology properties"""
		# instance 实例
		name = Preprocessor.name_underline(d['name'])
		toolClass = tool_class(d['name'])
		tool = toolClass(name, prefLabel=locstr(d['name'], lang='en'))
		tool.isToolOfSoftware.append(cyber.TauDEM)
		tool.identifier = name
		description = OWLUtils.join_list(d['description'])
		keywords = OWLUtils.to_keywords(description)
		keywords.extend(name.replace('_', ' ').split(' '))
		# keywords=name.replace('_', ' ').split(' ')
		OWLUtils.link_to_domain_concept(tool, keywords)

		for k, v in d.items():
			# 外层, 参数
			if (k in ['parameters', 'options']) and type(v) == list:
				for i, item in enumerate(v):
					param = None
					# localname = v[i]['parameterName']
					localname = Preprocessor.space_2_underline(item['parameterName'])
					_label = localname.replace('_', ' ')
					if item['isInputFile']:
						param = TauDEMInput(localname, prefLabel=locstr(_label, lang='en'))
						# param = TauDEMInput(prefLabel=locstr(_label, lang='en'))
						# input geo data ? rule: format-> geoformat->geo data
						tool.input.append(param)
						handle_params(param, item)
						param.isInput = True
					elif item['isOutputFile']:  # localname.lower().startswith('output_', 0, len('output_')):
						param = TauDEMOutput(localname, prefLabel=locstr(_label, lang='en'))
						# param = TauDEMOutput(prefLabel=locstr(_label, lang='en'))
						tool.output.append(param)
						handle_params(param, item)
						param.isOutput = True
					else:
						param = TauDEMOption(localname, prefLabel=locstr(_label, lang='en'))
						# param = TauDEMOption(prefLabel=locstr(localname.replace('_', ' '), lang='en'))
						tool.option.append(param)
						handle_params(param, item)
					OWLUtils.link_to_domain_concept(param, _label)
					param.identifier = localname
			else:
				prop = get_property(k, DataProperty)
				if not v:
					continue
				if type(v) == list and len(v) > 0:
					v = ''.join(v)
				OWLUtils.set_data_property(tool, prop, v)
		# task
		handle_task(tool, name, d['name'], description)
		OWLUtils.application_category(tool, 'Geomorphometry', 'digital terrain analysis', 'hydrology')
Beispiel #3
0
def map_to_owl(json_data):
    for d in json_data:
        """mapping json data to ontology properties"""
        name = re.match("[0-9a-zA-Z\-/* ]+ (?=\([\w' ]+\))",
                        d['name'])  # 存在同名冲突
        if name:
            name_str = name.group().strip().lower().replace(' ', '_').replace(
                '/', '_')
        else:
            continue
        category = get_task_type(d['name'])
        toolCls = tool_class(category)
        # if already exists a instance has the same name
        if onto[name_str]:
            # if is the same
            if onto[name_str].syntax == d['syntax']:
                onto[name_str].is_a.append(toolCls)
                continue
            else:
                name_str = name_str + '_' + category.lower().replace(' ', '_')
        tool = toolCls(name_str,
                       prefLabel=locstr(name_str.replace('_', ' '), lang='en'))

        keywords = [name_str.replace('_', ' ')]
        OWLUtils.link_to_domain_concept(tool, keywords)

        tool.isToolOfSoftware.append(cyber.ArcGIS_Desktop)
        tool.identifier = name_str.replace('_', ' ')
        # tool.hasManualPageURL.append(d['manual_url'])
        tool.description.append(locstr(d['description'], lang='en'))
        tool.usage.append(OWLUtils.join_list(d['usage']))
        tool.syntax.append(d['syntax'])
        tool.example.append(handle_example(d['example']))
        handle_task(tool, d['name'], name_str, d['description'])
        for parameter in d['parameters']:
            handle_parameters(tool, parameter)