<commit_before>package org.cytoscape.webservice.psicquic.task;

/*
 * #%L
 * Cytoscape PSIQUIC Web Service Impl (webservice-psicquic-client-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.task.create.CreateNetworkViewTaskFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient;
import org.cytoscape.webservice.psicquic.PSIMI25VisualStyleBuilder;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient.SearchMode;
import org.cytoscape.webservice.psicquic.RegistryManager;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportNetworkFromPSICQUICTask extends AbstractTask implements ObservableTask {

	private static final Logger logger = LoggerFactory.getLogger(ImportNetworkFromPSICQUICTask.class);

	private final PSICQUICRestClient client;
	private final CyNetworkManager manager;
	private final RegistryManager registryManager;

	// TaskFactory for creating view
	private final CreateNetworkViewTaskFactory createViewTaskFactory;

	private String query;
	private Collection<String> targetServices;

	private Set<String> searchResult;
	private Map<String, CyNetwork> result;

	private SearchRecoredsTask searchTask;

	private final SearchMode mode;
	private final boolean mergeNetworks;

	private final PSIMI25VisualStyleBuilder vsBuilder;
	private final VisualMappingManager vmm;

	private volatile boolean canceled = false;

	public ImportNetworkFromPSICQUICTask(final String query, final PSICQUICRestClient client,
			final CyNetworkManager manager, final RegistryManager registryManager, final Set<String> searchResult,
			final SearchMode mode, final CreateNetworkViewTaskFactory createViewTaskFactory,
			final PSIMI25VisualStyleBuilder vsBuilder, final VisualMappingManager vmm, final boolean toCluster) {
		this.client = client;
		this.manager = manager;
		this.registryManager = registryManager;
		this.query = query;
		this.mergeNetworks = toCluster;

		this.searchResult = searchResult;
		this.mode = mode;
		this.createViewTaskFactory = createViewTaskFactory;
		this.vmm = vmm;
		this.vsBuilder = vsBuilder;
	}

	public ImportNetworkFromPSICQUICTask(final String query, final PSICQUICRestClient client,
			final CyNetworkManager manager, final RegistryManager registryManager, final SearchRecoredsTask searchTask,
			final SearchMode mode, final CreateNetworkViewTaskFactory createViewTaskFactory,
			final PSIMI25VisualStyleBuilder vsBuilder, final VisualMappingManager vmm) {

		this.client = client;
		this.manager = manager;
		this.registryManager = registryManager;
		this.query = query;
		this.mergeNetworks = false;
		this.searchTask = searchTask;
		this.mode = mode;
		this.createViewTaskFactory = createViewTaskFactory;

		this.vmm = vmm;
		this.vsBuilder = vsBuilder;
	}

	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {
		taskMonitor.setTitle("Importing Interacitons from PSICQUIC Services");
		taskMonitor.setStatusMessage("Loading interaction from remote service...");
		taskMonitor.setProgress(0.01d);

		if (searchResult == null)
			processSearchResult();
		else
			targetServices = searchResult;

		if (searchResult == null)
			throw new NullPointerException("Could not find search result");
		if (query == null)
			throw new NullPointerException("Query is null");
		if (targetServices == null)
			throw new NullPointerException("Target service set is null");

		// Switch task type based on the user option.

		final Date date = new Date();<commit_msg>Typo fixed in status message.<commit_after>package org.cytoscape.webservice.psicquic.task;

/*
 * #%L
 * Cytoscape PSIQUIC Web Service Impl (webservice-psicquic-client-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.task.create.CreateNetworkViewTaskFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient;
import org.cytoscape.webservice.psicquic.PSIMI25VisualStyleBuilder;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient.SearchMode;
import org.cytoscape.webservice.psicquic.RegistryManager;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportNetworkFromPSICQUICTask extends AbstractTask implements ObservableTask {

	private static final Logger logger = LoggerFactory.getLogger(ImportNetworkFromPSICQUICTask.class);

	private final PSICQUICRestClient client;
	private final CyNetworkManager manager;
	private final RegistryManager registryManager;

	// TaskFactory for creating view
	private final CreateNetworkViewTaskFactory createViewTaskFactory;

	private String query;
	private Collection<String> targetServices;

	private Set<String> searchResult;
	private Map<String, CyNetwork> result;

	private SearchRecoredsTask searchTask;

	private final SearchMode mode;
	private final boolean mergeNetworks;

	private final PSIMI25VisualStyleBuilder vsBuilder;
	private final VisualMappingManager vmm;

	private volatile boolean canceled = false;

	public ImportNetworkFromPSICQUICTask(final String query, final PSICQUICRestClient client,
			final CyNetworkManager manager, final RegistryManager registryManager, final Set<String> searchResult,
			final SearchMode mode, final CreateNetworkViewTaskFactory createViewTaskFactory,
			final PSIMI25VisualStyleBuilder vsBuilder, final VisualMappingManager vmm, final boolean toCluster) {
		this.client = client;
		this.manager = manager;
		this.registryManager = registryManager;
		this.query = query;
		this.mergeNetworks = toCluster;

		this.searchResult = searchResult;
		this.mode = mode;
		this.createViewTaskFactory = createViewTaskFactory;
		this.vmm = vmm;
		this.vsBuilder = vsBuilder;
	}

	public ImportNetworkFromPSICQUICTask(final String query, final PSICQUICRestClient client,
			final CyNetworkManager manager, final RegistryManager registryManager, final SearchRecoredsTask searchTask,
			final SearchMode mode, final CreateNetworkViewTaskFactory createViewTaskFactory,
			final PSIMI25VisualStyleBuilder vsBuilder, final VisualMappingManager vmm) {

		this.client = client;
		this.manager = manager;
		this.registryManager = registryManager;
		this.query = query;
		this.mergeNetworks = false;
		this.searchTask = searchTask;
		this.mode = mode;
		this.createViewTaskFactory = createViewTaskFactory;

		this.vmm = vmm;
		this.vsBuilder = vsBuilder;
	}

	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {
		taskMonitor.setTitle("Importing Interactions from PSICQUIC Services");
		taskMonitor.setStatusMessage("Loading interactions from remote service...");
		taskMonitor.setProgress(0.01d);

		if (searchResult == null)
			processSearchResult();
		else
			targetServices = searchResult;

		if (searchResult == null)
			throw new NullPointerException("Could not find search result");
		if (query == null)
			throw new NullPointerException("Query is null");
		if (targetServices == null)
			throw new NullPointerException("Target service set is null");

		// Switch task type based on the user option.

		final Date date = new Date();
{'fraction_non_alphanumeric': 0.07489815104982764, 'fraction_numerical': 0.005223023085762039, 'mean_word_length': 5.290407358738502, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3322663', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2686, 'n_words': 807}