<commit_before>/* Copyright 2014 MITRE Corporation
 *
 * 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.
 */
package org.mitre.provenance.dag;

import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.core.util.MultivaluedMapImpl;

/**
 * Controls the settings that the graph traverser uses to determine
 * what to return in response to a given query.
 * 
 * <p>This object provides relatively fine-grained control over what kind of
 * provenance graph to discover from the database.
 * 
 * <p>Creating default instances of this object will traverse the graph in both directions.
 * 
 * <P>Specific objects can be created idiomatically by using the chaining methods specified below, such as:
 * 
 * <pre>new TraversalSettings().onlyForward().setMaxDepth(1).excludeEdges().includeNodes();</pre>
 * 
 * <p>For example, that will create a TraversalSettings object that instructs the code to fetch all nodes forward of
 * a starting point, only one hop away, returning a set of nodes but not edges.
 * @author DMALLEN
 */
public class TraversalSettings {
	public static final TraversalSettings UNLIMITED = new TraversalSettings(-1, -1, true, true, true, true, true, true, true);
	public static final TraversalSettings UNLIMITED_PROVENANCE_ONLY = new TraversalSettings(-1, -1, true, true, true, false, false, true, true);
	
	/** The maximum number of nodes to return */
	public int n = 200;
	
	/** The maximum depth away from the starting point to visit.
	 * A value of less than or equal to zero means no limit. 
	 */
	public int maxDepth = 10;
	
	/** If true, breadth first will be used.  If false, depth first */
	public boolean breadthFirst = true; 
	
	/** Whether the result should include nodes */
	public boolean includeNodes = true;
	
	/** Whether the result should include edges */
	public boolean includeEdges = true;
	
	/** Whether the result should include non-provenance edges */
	public boolean includeNPEs = true;
	
	/** Whether or not NPIDs should be followed when 
	 * discovering new nodes in the graph.
	 */
	public boolean followNPIDs = true;
	
	/** Whether or not to traverse forward in the DAG */
	public boolean forward = true;
	
	/** Whether or not to traverse backwards in the DAG */
	public boolean backward = true;
	
	/** Whether or not to expand workflows. */
	public boolean expandWorkflows = true; 
	
	private TraversalSettings(int n, int maxDepth, boolean breadthFirst, boolean includeNodes, boolean includeEdges, 
			boolean includeNPEs, boolean followNPIDs, boolean forward, boolean backward) {
		this.n = n;
		this.maxDepth = maxDepth;
		this.breadthFirst = breadthFirst;
		this.includeNodes = includeNodes;
		this.includeEdges = includeEdges;
		this.includeNPEs = includeNPEs;
		this.followNPIDs = followNPIDs;
		this.forward = forward;
		this.backward = backward;
	}
	
	public TraversalSettings() {
		this(200, 10, true, true, true, true, true, true, true);
	}
	
	/** Traversal will not expand workflows (that is, will keep them individual nodes) */
	public TraversalSettings dontExpandWorkflows() { expandWorkflows = false; return this; } 
	
	/** Traversal will expand workflows (that is, expand their members and traverse them) */
	public TraversalSettings expandWorkflows() { expandWorkflows = true; return this; } 
	
	/** Traversal will not follow non-provenance edges/IDs */
	public TraversalSettings ignoreNPIDs() { followNPIDs = false; return this; }
	
	/** Traversal will follow non-provenance edges/IDs. */
	public TraversalSettings followNPIDs() { followNPIDs = true; return this; }
	
	/** Traversal will go both forwards and backwards (upstream/downstream) */
	public TraversalSettings bothWays() { forward = true; backward = true; return this; } 
	
	/** Traversal will go forward only */
	public TraversalSettings onlyForward() { forward = true; backward = false; return this; }
	
	/* Traversal will go backward only */<commit_msg>added setN() mutator<commit_after>/* Copyright 2014 MITRE Corporation
 *
 * 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.
 */
package org.mitre.provenance.dag;

import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.core.util.MultivaluedMapImpl;

/**
 * Controls the settings that the graph traverser uses to determine
 * what to return in response to a given query.
 * 
 * <p>This object provides relatively fine-grained control over what kind of
 * provenance graph to discover from the database.
 * 
 * <p>Creating default instances of this object will traverse the graph in both directions.
 * 
 * <P>Specific objects can be created idiomatically by using the chaining methods specified below, such as:
 * 
 * <pre>new TraversalSettings().onlyForward().setMaxDepth(1).excludeEdges().includeNodes();</pre>
 * 
 * <p>For example, that will create a TraversalSettings object that instructs the code to fetch all nodes forward of
 * a starting point, only one hop away, returning a set of nodes but not edges.
 * @author DMALLEN
 */
public class TraversalSettings {
	public static final TraversalSettings UNLIMITED = new TraversalSettings(-1, -1, true, true, true, true, true, true, true);
	public static final TraversalSettings UNLIMITED_PROVENANCE_ONLY = new TraversalSettings(-1, -1, true, true, true, false, false, true, true);
	
	/** The maximum number of nodes to return */
	public int n = 200;
	
	/** The maximum depth away from the starting point to visit.
	 * A value of less than or equal to zero means no limit. 
	 */
	public int maxDepth = 10;
	
	/** If true, breadth first will be used.  If false, depth first */
	public boolean breadthFirst = true; 
	
	/** Whether the result should include nodes */
	public boolean includeNodes = true;
	
	/** Whether the result should include edges */
	public boolean includeEdges = true;
	
	/** Whether the result should include non-provenance edges */
	public boolean includeNPEs = true;
	
	/** Whether or not NPIDs should be followed when 
	 * discovering new nodes in the graph.
	 */
	public boolean followNPIDs = true;
	
	/** Whether or not to traverse forward in the DAG */
	public boolean forward = true;
	
	/** Whether or not to traverse backwards in the DAG */
	public boolean backward = true;
	
	/** Whether or not to expand workflows. */
	public boolean expandWorkflows = true; 
	
	private TraversalSettings(int n, int maxDepth, boolean breadthFirst, boolean includeNodes, boolean includeEdges, 
			boolean includeNPEs, boolean followNPIDs, boolean forward, boolean backward) {
		this.n = n;
		this.maxDepth = maxDepth;
		this.breadthFirst = breadthFirst;
		this.includeNodes = includeNodes;
		this.includeEdges = includeEdges;
		this.includeNPEs = includeNPEs;
		this.followNPIDs = followNPIDs;
		this.forward = forward;
		this.backward = backward;
	}
	
	public TraversalSettings() {
		this(200, 10, true, true, true, true, true, true, true);
	}
	
	/** Traversal will not expand workflows (that is, will keep them individual nodes) */
	public TraversalSettings dontExpandWorkflows() { expandWorkflows = false; return this; } 
	
	/** Traversal will expand workflows (that is, expand their members and traverse them) */
	public TraversalSettings expandWorkflows() { expandWorkflows = true; return this; } 
	
	/** Traversal will not follow non-provenance edges/IDs */
	public TraversalSettings ignoreNPIDs() { followNPIDs = false; return this; }
	
	/** Traversal will follow non-provenance edges/IDs. */
	public TraversalSettings followNPIDs() { followNPIDs = true; return this; }
	
	/** Traversal will go both forwards and backwards (upstream/downstream) */
	public TraversalSettings bothWays() { forward = true; backward = true; return this; } 
	
	/** Set the maximum number of nodes to return */
	public TraversalSettings setN(int n) { this.n = n; return this; } 
	
	/** Traversal will go forward only */
	public TraversalSettings onlyForward() { forward = true; backward = false; return this; }
	
	/* Traversal will go backward only */
{'fraction_non_alphanumeric': 0.08577852726250702, 'fraction_numerical': 0.005171444631815627, 'mean_word_length': 4.003374578177728, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6959562', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2367, 'n_words': 1032}