All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eduworks.cruncher.ontology.CruncherOntologyTDBLoader Maven / Gradle / Ivy

There is a newer version: 5.16.4
Show newest version
package com.eduworks.cruncher.ontology;

import java.io.File;
import java.io.InputStream;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.eduworks.ontology.Ontology;
import com.eduworks.resolver.Context;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.ReadWrite;

public class CruncherOntologyTDBLoader extends CruncherOntology
{

	@Override
	public Object resolve(Context c, Map parameters, Map dataStreams) throws JSONException
	{
		String inputDirectory = decodeValue(optAsString("input", "", c, parameters, dataStreams));

		String extension = decodeValue(optAsString("extension", "", c, parameters, dataStreams));

		String tdbDirectory = decodeValue(optAsString("tdbDirectory", "", c, parameters, dataStreams));

		String identifier = decodeValue(optAsString("identifier", "", c, parameters, dataStreams));

		Dataset tdbDataset = getDataSet(tdbDirectory,ReadWrite.WRITE,c);

		try
		{
			File input = new File(inputDirectory);

			if (input.isDirectory())
			{
				File[] files = input.listFiles();

				for (File file : files)
				{
					if (file.getName().endsWith(extension))
					{
						identifier = file.getName().substring(0, file.getName().length() - extension.length());

						Ontology.importToTDB(tdbDataset, file.getPath().replace(File.separatorChar, '/'), identifier);
					}
				}
			}
			else
			{
				if (!identifier.isEmpty())
				{
					Ontology.importToTDB(tdbDataset, input.getPath().replace(File.separatorChar, '/'), identifier);
				}
				else
				{
					Ontology.importToTDB(tdbDataset, input.getPath().replace(File.separatorChar, '/'),
							input.getName().substring(0, input.getName().indexOf(".")));
				}
			}
		}
		finally
		{
		}

		return true;
	}

	@Override
	public String getDescription()
	{
		return "adds an import statement to the ontology specified by ontologyId to import the ontology specified with importId";
	}

	@Override
	public String getReturn()
	{
		return "Object";
	}

	@Override
	public String getAttribution()
	{
		return ATTRIB_NONE;
	}

	@Override
	public JSONObject getParameters() throws JSONException
	{
		return jo("ontologyId", "string", "directory", "path string", "importId", "string");
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy