<commit_before>/*******************************************************************************
 * Copyright 2012 University of Southern California
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * 	http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This code was developed by the Information Integration Group as part 
 * of the Karma project at the Information Sciences Institute of the 
 * University of Southern California.  For more information, publications, 
 * and related projects, please see: http://www.isi.edu/integration
 ******************************************************************************/
package edu.isi.karma.webserver;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.isi.karma.controller.update.UpdateContainer;
import edu.isi.karma.controller.update.WorksheetHierarchicalDataUpdate;
import edu.isi.karma.controller.update.WorksheetHierarchicalHeadersUpdate;
import edu.isi.karma.controller.update.WorksheetListUpdate;
import edu.isi.karma.imp.csv.CSVFileImport;
import edu.isi.karma.modeling.ontology.OntologyManager;
import edu.isi.karma.rep.Workspace;
import edu.isi.karma.rep.WorkspaceManager;
import edu.isi.karma.rep.metadata.Tag;
import edu.isi.karma.rep.metadata.TagsContainer.Color;
import edu.isi.karma.rep.metadata.TagsContainer.TagName;
import edu.isi.karma.view.VWorksheet;
import edu.isi.karma.view.VWorkspace;

public class GetExampleJSON extends HttpServlet {
	private enum Arguments {
		hasPreferenceId, workspacePreferencesId
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static Logger logger = LoggerFactory.getLogger(GetExampleJSON.class);

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Workspace workspace = WorkspaceManager.getInstance().getFactory()
				.createWorkspace();

		/* Check if any workspace id is set in cookies. */
		boolean hasWorkspaceCookieId = request.getParameter(Arguments.hasPreferenceId.name()).equals("true");
		VWorkspace vwsp = null;
		File crfModelFile = null;
		
		/* If set, pick the right preferences and CRF Model file */
		if(hasWorkspaceCookieId) {
			String cachedWorkspaceId = request.getParameter(Arguments.workspacePreferencesId.name());
			vwsp = new VWorkspace(workspace, cachedWorkspaceId);
			crfModelFile = new File("./CRF_Models/"+cachedWorkspaceId+"_CRFModel.txt");
		} else {
			vwsp = new VWorkspace(workspace);
			crfModelFile = new File("./CRF_Models/"+workspace.getId()+"_CRFModel.txt");
		}
		/* Read and populate CRF Model from a file */
		if(!crfModelFile.exists())
			crfModelFile.createNewFile();
		boolean result = workspace.getCrfModelHandler().readModelFromFile(crfModelFile.getAbsolutePath());
		if (!result)
			logger.error("Error occured while reading CRF Model!");
		
		WorkspaceRegistry.getInstance().register(new ExecutionController(vwsp));
		
		// Loading ontology to be preloaded
		OntologyManager mgr = workspace.getOntologyManager();
		//mgr.doImport(new File("./Preloaded_Ontologies/geo_2007.owl"));
		mgr.doImport(new File("./Preloaded_Ontologies/oilwell.owl"));
		//mariam
		
//		File file = new File("../demofiles/peopleFaculty.csv");
		/*
		File file = new File("../demofiles/usc_faculty.csv");
		CSVFileImport imp = new CSVFileImport(1, 2, ',', '"', file, workspace.getFactory(), workspace);
		imp.generateWorksheet();
		*/
		File file = new File("./SampleData/CSV/peopleFaculty.csv");
		CSVFileImport imp = new CSVFileImport(1, 2, ',', '"', file, workspace.getFactory(), workspace);
		imp.generateWorksheet();
		/*
		//load ontologies
		OntologyManager om = workspace.getOntologyManager();
		
		//vivo ontology
/*
		om.doImport(new File("../demofiles/vivo1.4-protege.owl"));
		//rdfs ontology
		om.doImport(new File("../demofiles/rdfs-small.owl"));<commit_msg>removed reference to Sampledata<commit_after>/*******************************************************************************
 * Copyright 2012 University of Southern California
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * 	http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This code was developed by the Information Integration Group as part 
 * of the Karma project at the Information Sciences Institute of the 
 * University of Southern California.  For more information, publications, 
 * and related projects, please see: http://www.isi.edu/integration
 ******************************************************************************/
package edu.isi.karma.webserver;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.isi.karma.controller.update.UpdateContainer;
import edu.isi.karma.controller.update.WorksheetHierarchicalDataUpdate;
import edu.isi.karma.controller.update.WorksheetHierarchicalHeadersUpdate;
import edu.isi.karma.controller.update.WorksheetListUpdate;
import edu.isi.karma.imp.csv.CSVFileImport;
import edu.isi.karma.modeling.ontology.OntologyManager;
import edu.isi.karma.rep.Workspace;
import edu.isi.karma.rep.WorkspaceManager;
import edu.isi.karma.rep.metadata.Tag;
import edu.isi.karma.rep.metadata.TagsContainer.Color;
import edu.isi.karma.rep.metadata.TagsContainer.TagName;
import edu.isi.karma.view.VWorksheet;
import edu.isi.karma.view.VWorkspace;

public class GetExampleJSON extends HttpServlet {
	private enum Arguments {
		hasPreferenceId, workspacePreferencesId
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static Logger logger = LoggerFactory.getLogger(GetExampleJSON.class);

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Workspace workspace = WorkspaceManager.getInstance().getFactory()
				.createWorkspace();

		/* Check if any workspace id is set in cookies. */
		boolean hasWorkspaceCookieId = request.getParameter(Arguments.hasPreferenceId.name()).equals("true");
		VWorkspace vwsp = null;
		File crfModelFile = null;
		
		/* If set, pick the right preferences and CRF Model file */
		if(hasWorkspaceCookieId) {
			String cachedWorkspaceId = request.getParameter(Arguments.workspacePreferencesId.name());
			vwsp = new VWorkspace(workspace, cachedWorkspaceId);
			crfModelFile = new File("./CRF_Models/"+cachedWorkspaceId+"_CRFModel.txt");
		} else {
			vwsp = new VWorkspace(workspace);
			crfModelFile = new File("./CRF_Models/"+workspace.getId()+"_CRFModel.txt");
		}
		/* Read and populate CRF Model from a file */
		if(!crfModelFile.exists())
			crfModelFile.createNewFile();
		boolean result = workspace.getCrfModelHandler().readModelFromFile(crfModelFile.getAbsolutePath());
		if (!result)
			logger.error("Error occured while reading CRF Model!");
		
		WorkspaceRegistry.getInstance().register(new ExecutionController(vwsp));
		
		// Loading ontology to be preloaded
		OntologyManager mgr = workspace.getOntologyManager();
		//mgr.doImport(new File("./Preloaded_Ontologies/geo_2007.owl"));
		mgr.doImport(new File("./Preloaded_Ontologies/oilwell.owl"));
		//mariam
		
//		File file = new File("../demofiles/peopleFaculty.csv");
		/*
		File file = new File("../demofiles/usc_faculty.csv");
		CSVFileImport imp = new CSVFileImport(1, 2, ',', '"', file, workspace.getFactory(), workspace);
		imp.generateWorksheet();
		*/
		/*
		//load ontologies
		OntologyManager om = workspace.getOntologyManager();
		
		//vivo ontology
/*
		om.doImport(new File("../demofiles/vivo1.4-protege.owl"));
		//rdfs ontology
		om.doImport(new File("../demofiles/rdfs-small.owl"));
{'fraction_non_alphanumeric': 0.1420752820283704, 'fraction_numerical': 0.0044677761644141625, 'mean_word_length': 4.937665782493369, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432773', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2591, 'n_words': 645}