Beispiel #1
0
def handle_inout(tool, item_value, in_or_out):
    for ioD in item_value:
        # print(ioD)
        io_name = ioD['name']
        if io_name is None:
            io_name = in_or_out
        _name = Preprocessor.io_name(io_name, onto)
        param_rdf = None
        if in_or_out == 'input':
            param = SagaInput(_name, prefLabel=locstr(io_name, lang='en'))
            # param = SagaInput(0,prefLabel=locstr(io_name, lang='en')) # blank node prefix with _:
            tool.input.append(param)
            param.isInput = True
            # rdflib
            param_rdf = URIRef(param.iri)
            with onto:
                g.add((param_rdf, RDF.type, Sh.NodeShape))
                g.add((param_rdf, RDF.type, URIRef(SagaInput.iri)))
        else:
            param = SagaOutput(_name, prefLabel=locstr(io_name, lang='en'))
            # param =SagaOutput(0, prefLabel=locstr(io_name, lang='en'))
            tool.output.append(param)
            param.isOutput = True
            # rdflib
            param_rdf = URIRef(param.iri)
            with onto:
                g.add((param_rdf, RDF.type, Sh.NodeShape))
                g.add((param_rdf, RDF.type, URIRef(SagaOutput.iri)))

        if ioD['dataType']:
            vr = re.match("[a-zA-Z ]+ (?=\([a-zA-Z ]+\))?", ioD['dataType'])
            dformat = vr.group().strip()
            if not get_format(dformat):
                continue
            param.supportsDataFormat.append(data[get_format(dformat)])
            # rdflib
            formatshape = g.BNode()
            with onto:
                g.add((param_rdf, Sh.property, formatshape))
                g.add((formatshape, RDF.type, Sh.PropertyShape))
                g.add((formatshape, Sh.path, Cyber.supportsDataFormat))
            formats = g.BNode()
            with onto:
                g.add((formats, RDF.first, [data[get_format(dformat)]]))
                g.add((formats, RDF.rest, RDF.nil))
                c = Collection(g, formats)
                g.add((formatshape, Sh['in'], c))

        param.identifier = ioD['name']
        param.description.append(ioD['description'])
        param.flag = ioD['flag']
        param.isOptional = ioD['isOptional']
        OWLUtils.link_to_domain_concept(param, io_name.replace('_', ' '))
        # shacl
        pshape = Sh.PropertyShape(0)
        pshape.path = onto.dataContent
        if not ioD['isOptional']:
            pshape.minCount = 1
            pshape.message.append(ioD['name'] + " is required!")
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 = 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 #4
0
def handle_parameters(tool, param, _onto):
    # 部分parameter不包含isInputFile等属性
    name = param['parameter']
    _name = Preprocessor.io_name(param['parameter'], _onto, ['overwrite'])
    if 'isInputFile' in param.keys() and param['isInputFile']:
        p = GrassInput(_name, prefLabel=locstr(name, lang='en'))
        # p = GrassInput(0, prefLabel=locstr(name, lang='en'))
        tool.input.append(p)
        p.isInput = param['isInputFile']
        OWLUtils.link_to_domain_concept(p, name.replace('_', ' '))
    elif 'isOutputFile' in param.keys() and param['isOutputFile']:
        p = GrassOutput(_name, prefLabel=locstr(name, lang='en'))
        # p = GrassOutput(0, prefLabel=locstr(name, lang='en'))
        tool.output.append(p)
        p.isOutput = param['isOutputFile']
        OWLUtils.link_to_domain_concept(p, name.replace('_', ' '))
    else:
        p = GrassOption(_name, prefLabel=locstr(name, lang='en'))
        # p = GrassOption(0, prefLabel=locstr(name, lang='en'))
        tool.option.append(p)
    p.flag = param['flag']
    p.identifier = name
    if 'dataType' in param.keys():
        p.datatypeInString.append(param['dataType'])
        p.datatype.append(OWLUtils.get_datatype_iris(param['dataType']))
    p.description.append(param['explanation'])
    if 'defaultValue' in param.keys():
        if param['defaultValue'] is not None:
            p.defaultValue = param['defaultValue']
    p.isOptional = param['isOptional']
    if 'alternatives' in param.keys():
        alternatives = param['alternatives']
        if alternatives:
            literal = True
            if param['explanation'] == "Name of Modules":
                literal = False
            if len(alternatives) > 1:
                _onto, l = OWLUtils.resources_2_rdf_list(
                    _onto, alternatives, literal)
                p.availableList.append(l)
                for value in alternatives:
                    p.availableValue.append(value)
            else:
                if re.match('[-0-9]+-[0-9]+', alternatives[0]):
                    p.minimum = alternatives[0].rsplit('-', 1)[0]
                    p.maximum = alternatives[0].rsplit('-', 1)[1]
                elif re.match('[-0-9]+-[a-zA-Z<> ]+', alternatives[0]):
                    p.minimum = alternatives[0].split('-')[0]
                p.comment.append('Options: ' + ' '.join(alternatives))
Beispiel #5
0
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()
Beispiel #6
0
def handle_parameter(tool, param):
	pname = param['name']
	p = None
	_name = Preprocessor.io_name(pname, onto, common_options)
	if 'isInputFile' in param.keys():
		p = GDALInput(_name, prefLabel=locstr(pname, lang='en'))
		p.isInput = True
		tool.input.append(p)
		OWLUtils.link_to_domain_concept(p, pname.replace('_', ' '))
	elif "isOutputFile" in param.keys():
		p = GDALOutput(_name, prefLabel=locstr(pname, lang='en'))
		p.isOutput = True
		tool.output.append(p)
		OWLUtils.link_to_domain_concept(p, pname.replace('_', ' '))
	p.identifier = pname
	if param['flag']: p.flag = param['flag']
	p.isOptional = param['isOptional']
	p.description.append(locstr(param['explanation'], lang='en'))
	p.datatype.append(OWLUtils.get_datatype_iris(param['dataType']))
Beispiel #7
0
def map_to_owl(json_data):
	for d in json_data:
		toolClass = tool_class(d['category'])
		name = Preprocessor.toolname_underline(d['title'])
		tool = toolClass(name, prefLabel=locstr(d['title'], lang='en'))
		tool.isToolOfSoftware.append(cyber.Whitebox_Tools)
		tool.identifier = name
		tool.manualPageURL.append('https://github.com/jblindsay/whitebox-tools/blob/master/manual/WhiteboxToolsManual.md')
		tool.executable = 'whitebox_tools'
		tool.commandLine.append(d['parameter_commandline'][0])
		tool.description.append(locstr(d['description'], lang='en'))

		keywords = OWLUtils.to_keywords(d['description'])
		keywords.extend(d['title'].split(" "))
		OWLUtils.link_to_domain_concept(tool, keywords)

		handle_task(tool, d['category'], d['title'], d['description'])
		OWLUtils.application_category(tool, [], d['category'].replace(' Tools', ''), [])
		for parameter in d['parameter']:
			handle_parameter(tool, parameter)
Beispiel #8
0
def map_to_owl(json_data):
	for d in json_data:
		name = d['name']
		toolClass = tool_class(name)
		name = Preprocessor.space_2_underline(name)
		tool = toolClass(name, prefLabel=locstr(name, lang='en'))
		tool.isToolOfSoftware.append(cyber.GDAL)
		tool.identifier = name
		tool.definition = d['summary']
		tool.manualPageURL.append(d['manual_url'])
		tool.executable = d['exec']
		tool.commandLine.append(d['syntax'])
		tool.description.append(locstr(d['description'], lang='en'))
		OWLUtils.application_category(tool, [], ['GIS Analysis'], [str(toolClass.name).replace('Programs', '')])
		keywords = OWLUtils.to_keywords(d['description'])
		OWLUtils.link_to_domain_concept(tool, keywords)
		for example in d['example']:
			tool.example.append(example)
		handle_task(tool, d['name'], d['description'])
		for parameter in d['parameters']:
			handle_parameter(tool, parameter)
		for option in d['options']:
			handle_options(tool, option, onto)
Beispiel #9
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)
Beispiel #10
0
def handle_parameters(tool, param):
    # 部分parameter不包含isInputFile等属性
    _name = Preprocessor.io_name(param['name'], onto)
    if 'isInputFile' in param.keys() and param['isInputFile']:
        p = ArcGISInput(_name, prefLabel=locstr(param['name'], lang='en'))
        # p = ArcGISInput(0, prefLabel=locstr(param['name'], lang='en'))
        tool.input.append(p)
        p.isInput = param['isInputFile']
        OWLUtils.link_to_domain_concept(p, param['name'].replace('_', ' '))
    elif 'isOutputFile' in param.keys() and param['isOutputFile']:
        p = ArcGISOutput(_name, prefLabel=locstr(param['name'], lang='en'))
        # p = ArcGISOutput(0, prefLabel=locstr(param['name'], lang='en'))
        tool.output.append(p)
        p.isOutput = param['isOutputFile']
        OWLUtils.link_to_domain_concept(p, param['name'].replace('_', ' '))
    else:
        p = ArcGISOption(_name, prefLabel=locstr(param['name'], lang='en'))
        # p = ArcGISOption(0, prefLabel=locstr(param['name'], lang='en'))
        tool.option.append(p)
        dt = param['dataType']
        if dt:
            p.datatypeInString.append(param['dataType'])
            p.datatype.append(OWLUtils.get_datatype_iris(param['dataType']))
        OWLUtils.link_to_domain_concept(p, param['name'].replace('_', ' '))
    p.identifier = param['name']
    p.flag = param['name']
    if 'dataType' in param.keys() and param['dataType']:
        p.datatypeInString.append(param['dataType'])
    p.description.append(param['description'])
    p.isOptional = param['isOptional']
    # datatype
    datatype = param['dataType']
    if datatype is None: datatype = "string"
    dt = datatype.strip().lower().replace(' ', '_')
    # print(dt)
    dtype = data[dt]
    if dtype is None: dtype = OWLUtils.get_datatype_iris(dt)
    p.datatype.append(dtype)
    if "available_values" in param.keys():
        for value in param['available_values']:
            p.availableValue.append(value)
Beispiel #11
0
def handle_parameter(tool, param):
	# p = None
	dformat = file_type(param['flag'], tool.commandLine[0])
	ptype = param_type(param['description'])
	if 'flag_long' in param.keys():
		pname = param['flag_long'].replace('--', '')
	else:
		pname = param['flag'].replace('--', '')
	_name =  Preprocessor.io_name(pname, onto)
	if ptype == 1:
		p = WhiteboxInput(_name, prefLabel=locstr(pname, lang='en'))
		# p = OTBInput(0, prefLabel=locstr(param['name'], lang='en'))
		tool.input.append(p)
		p.isInput = True
		OWLUtils.link_to_domain_concept(p, pname.replace('_', ' '))
	elif ptype == 2:
		p = WhiteboxOutput(_name, prefLabel=locstr(pname, lang='en'))
		# p = OTBOutput(0, prefLabel=locstr(param['parameter_name'], lang='en'))
		tool.output.append(p)
		p.isOutput = True
		OWLUtils.link_to_domain_concept(p, pname.replace('_', ' '))
	elif ptype == 3:
		p = WhiteboxOption(_name, prefLabel=locstr(pname, lang='en'))
		tool.option.append(p)
		p.isOptional = True
		OWLUtils.link_to_domain_concept(p, pname.replace('_', ' '))
	else:
		p = WhiteboxOption(_name, prefLabel=locstr(pname, lang='en'))
		tool.option.append(p)
		avaliable_choices(p, param['description'])
	if dformat:
		p.supportsDataFormat = dformat
	p.identifier = pname
	p.flag = param['flag']
	if 'flag_long' in param.keys():
		p.longFlag.append(param['flag_long'])
	p.description.append(locstr(param['description'], lang='en'))