Issues fixity check, return parsed graph

		Args:
			None

		Returns:
			(dict): ('verdict':(bool): verdict of fixity check, 'premis_graph':(rdflib.Graph): parsed PREMIS graph from check)
348467
def fixity(self, response_format=None):

		'''
		
		'''

		# if no response_format, use default
		if not response_format:
			response_format = self.repo.default_serialization

		# issue GET request for fixity check
		response = self.repo.api.http_request('GET', '%s/fcr:fixity' % self.uri)

		# parse
		fixity_graph = self.repo.api.parse_rdf_payload(response.content, response.headers)

		# determine verdict
		for outcome in fixity_graph.objects(None, self.rdf.prefixes.premis.hasEventOutcome):
			if outcome.toPython() == 'SUCCESS':
				verdict = True
			else:
				verdict = False

		return {
			'verdict':verdict,
			'premis_graph':fixity_graph
		}
1271822
def parse_dot_data(s):
    
    global top_graphs
    top_graphs = list()
    try:
        graphparser = graph_definition()
        graphparser.parseWithTabs()
        tokens = graphparser.parseString(s)
        return list(tokens)
    except ParseException as err:
        print(
            err.line +
            " "*(err.column-1) + "^" +
            err)
        return None
1148286
def populate_from_trace_graph(self, graph: TraceGraph) -> None:
        
        # Track which trace frames have been visited as we populate the full
        # traces of the graph.
        self._visited_trace_frame_ids: Set[int] = set()

        self._populate_affected_issues(graph)

        if not self._affected_issues_only:
            # Finds issues from the conditions and saves them.
            # Also saves traces that have been trimmed to the affected
            # conditions.
            self._populate_issues_from_affected_trace_frames(graph)

            # Traces populated above may be missing all traces because
            # _populate_issues_from_affected_trace_frames only populates
            # traces that reach the affected conditions in one direction. We
            # may need to populate traces in other directions too.
            #
            # For example:
            #
            # Issue_x reaches affected_file_x via postcondition_x (forward
            # trace, i.e. trace leading to source). None of its backward
            # traces (leading to sinks) reach the affected files.
            #
            # _populate_issues_from_affected_trace_frames would have copied its
            # forward traces and trimmed it to those reaching postcondition_x.
            # We cannot blindly populate all forward traces in this case as
            # branches not leading to postcondition_x are unnecessary.
            #
            # However, in this specific example, all backward traces are needed
            # to give a complete picture of which sinks the issue reaches.
            # The following ensures that.
            for instance_id in self._issue_instances.keys():
                first_hop_ids = self._issue_instance_trace_frame_assoc[instance_id]
                fwd_trace_ids = {
                    tf_id
                    for tf_id in first_hop_ids
                    if self._trace_frames[tf_id].kind == TraceKind.POSTCONDITION
                }
                bwd_trace_ids = {
                    tf_id
                    for tf_id in first_hop_ids
                    if self._trace_frames[tf_id].kind == TraceKind.PRECONDITION
                }

                if len(fwd_trace_ids) == 0:
                    self._populate_issue_trace(
                        graph, instance_id, TraceKind.POSTCONDITION
                    )

                if len(bwd_trace_ids) == 0:
                    self._populate_issue_trace(
                        graph, instance_id, TraceKind.PRECONDITION
                    )
1203628
def _populate_issue_and_traces(self, graph: TraceGraph, instance_id: int) -> None:
        
        self._populate_issue(graph, instance_id)
        self._populate_issue_trace(graph, instance_id)
349857
def calculate_incorrect_name_dict(graph: BELGraph) -> Mapping[str, List[str]]:
    """"""
    missing = defaultdict(list)

    for namespace, name in _iterate_namespace_name(graph):
        missing[namespace].append(name)

    return dict(missing)
983591
def raise_for_old_graph(graph):
    
    graph_version = tokenize_version(graph.pybel_version)
    if graph_version < PYBEL_MINIMUM_IMPORT_VERSION:
        raise ImportVersionWarning(graph_version, PYBEL_MINIMUM_IMPORT_VERSION)
1139002
def complete(self, match, subject_graph):
        """"""
        size = len(match)
        # check whether we have an odd strong ring
        if match.forward[size-1] in subject_graph.neighbors[match.forward[size-2]]:
            # we have an odd closed cycle. check if this is a strong ring
            order = list(range(0, size, 2)) + list(range(1, size-1, 2))[::-1]
            ok = True
            for i in range(len(order)//2):
                # Count the number of paths between two opposite points in the
                # ring. Since the ring has an odd number of vertices, each
                # vertex has two semi-opposite vertices.
                count = len(list(subject_graph.iter_shortest_paths(
                    match.forward[order[i]],
                    match.forward[order[(i+size//2)%size]]
                )))
                if count > 1:
                    ok = False
                    break
                count = len(list(subject_graph.iter_shortest_paths(
                    match.forward[order[i]],
                    match.forward[order[(i+size//2+1)%size]]
                )))
                if count > 1:
                    ok = False
                    break
            if ok:
                match.ring_vertices = tuple(match.forward[i] for i in order)
                #print "RingPattern.complete: found odd ring"
                return True
            #print "RingPattern.complete: no odd ring"
        # check whether we have an even strong ring
        paths = list(subject_graph.iter_shortest_paths(
            match.forward[size-1],
            match.forward[size-2]
        ))
        #print "RingPattern.complete: even paths", paths
        if (size > 3 and len(paths) == 1 and len(paths[0]) == 3) or \
           (size == 3 and len(paths) == 2 and len(paths[0]) == 3):
            path = paths[0]
            if size == 3 and path[1] == match.forward[0]:
                path = paths[1]
            # we have an even closed cycle. check if this is a strong ring
            match.add_relation(size, path[1])
            size += 1
            order = list(range(0, size, 2)) + list(range(size-1, 0, -2))
            ok = True
            for i in range(len(order)//2):
                count = len(list(subject_graph.iter_shortest_paths(
                    match.forward[order[i]],
                    match.forward[order[(i+size//2)%size]]
                )))
                if count != 2:
                    ok = False
                    break
            if ok:
                # also check if this does not violate the requirement for a
                # unique origin:
                if match.forward[size-1] < match.forward[0]:
                    ok = False
            if not ok:
                vertex1 = match.forward[size-1]
                del match.forward[size-1]
                del match.reverse[vertex1]
                size -= 1
                #print "RingPattern.complete: no even ring"
            else:
                match.ring_vertices = tuple(match.forward[i] for i in order)
                #print "RingPattern.complete: found even ring"
            return ok
        #print "RingPattern.complete: not at all"
        return False
422294
def equiv_graph(self):
        
        eg = nx.Graph()
        for (u,v,d) in self.get_graph().edges(data=True):
            if d['pred'] == 'equivalentTo':
                eg.add_edge(u,v)
        return eg
1066095
def parse_reports(self, reports):
        
        violations_dict = defaultdict(list)
        for report in reports:
            if self.expression.flags & re.MULTILINE:
                matches = (match for match in
                           re.finditer(self.expression, report))
            else:
                matches = (self.expression.match(line) for line in
                           report.split('\n'))
            for match in matches:
                if match is not None:
                    src, line_number, message = match.groups()
                    # Transform src to a relative path, if it isn't already
                    src = os.path.relpath(src)
                    violation = Violation(int(line_number), message)
                    violations_dict[src].append(violation)
        return violations_dict
498799
def get_syntax_errors(graph: BELGraph) -> List[WarningTuple]:
    """"""
    return [
        (path, exc, an)
        for path, exc, an in graph.warnings
        if isinstance(exc, BELSyntaxError)
    ]
1073531
def fixpointmethod(self, cfg_node):
        
        JOIN = self.join(cfg_node)
        # Assignment check
        if isinstance(cfg_node, AssignmentNode):
            arrow_result = JOIN

            # Reassignment check
            if cfg_node.left_hand_side not in cfg_node.right_hand_side_variables:
                # Get previous assignments of cfg_node.left_hand_side and remove them from JOIN
                arrow_result = self.arrow(JOIN, cfg_node.left_hand_side)

            arrow_result = arrow_result | self.lattice.el2bv[cfg_node]
            constraint_table[cfg_node] = arrow_result
        # Default case
        else:
            constraint_table[cfg_node] = JOIN
111004
@SuppressWarnings("unchecked")
    public static IssueCategoryModel loadFromGraph(FramedGraph framedGraph, String issueCategoryID)
    {
        Iterable<Vertex> vertices = (Iterable<Vertex>)framedGraph.traverse(g -> framedGraph.getTypeResolver().hasType(g.V(), IssueCategoryModel.class))
                .traverse(g -> g.has(IssueCategoryModel.CATEGORY_ID, issueCategoryID)).getRawTraversal().toList();

        IssueCategoryModel result = null;
        for (Vertex vertex : vertices)
        {
            if (result != null)
                throw new DuplicateIssueCategoryException("Found more than one issue category for this id: " + issueCategoryID);

            result = framedGraph.frameElement(vertex, IssueCategoryModel.class);
        }
        return result;
    }
661112
def matcher(graph1, graph2, confidence=0.5, output_file="matching_results.csv", class_or_prop="classes", verbose=False):
	

	printDebug("----------\nNow matching...")

	f = open(output_file, 'wt')
	counter = 0

	try:
		writer = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
		writer.writerow( ('name 1', 'name 2', 'uri 1', 'uri 2') )

		# a) match classes

		if class_or_prop == "classes":

			for x in graph1.all_classes:
				l1 = unicode(x.bestLabel(qname_allowed=True))

				for y in graph2.all_classes:
					l2 = unicode(y.bestLabel(qname_allowed=True))

					if similar(l1, l2) > confidence:
						counter += 1
						row = [l1, l2, x.uri, y.uri]
						writer.writerow([s.encode('utf8') if type(s) is unicode else s for s in row])
						if verbose:
							print("%s ==~== %s" % (l1, l2))


		# b) match properties

		elif class_or_prop == "properties":

			for x in graph1.all_properties:
				l1 = unicode(x.bestLabel(qname_allowed=True))

				for y in graph2.all_properties:
					l2 = unicode(y.bestLabel(qname_allowed=True))

					if similar(l1, l2) > confidence:
						counter += 1
						row = [l1, l2, x.uri, y.uri]
						writer.writerow([s.encode('utf8') if type(s) is unicode else s for s in row])
						if verbose:
							print("%s ==~== %s" % (l1, l2))

	finally:
		f.close()

	printDebug("%d candidates found." % counter)
53948
def from_pickle(path: Union[str, BinaryIO], check_version: bool = True) -> BELGraph:
    
    graph = nx.read_gpickle(path)

    raise_for_not_bel(graph)
    if check_version:
        raise_for_old_graph(graph)

    return graph
344772
def get_graph(cls, response):
		
		if cls.is_graph(response):	# single graph object
			return response

		if hasattr(response, '__getitem__'):	# indexable tuple
			if len(response) > 0 and \
			   cls.is_graph(response[0]):	# graph object
				return response[0]
567697
def process_input_graph(func):
    """"""
    @wraps(func)
    def wrapped_func(*args, **kwargs):
        input_graph = args[0]
        if isinstance(input_graph, nx.DiGraph):
            return func(*args, **kwargs)
        else:
            nx_graph = dict_to_nx(args[0], oriented=True)
            args = [nx_graph] + list(args[1:])
            return func(*args, **kwargs)
    return wrapped_func
983078
def to_CAG(self):
        

        G = nx.DiGraph()
        for (name, attrs) in self.nodes(data=True):
            if attrs["type"] == "variable":
                for pred_fn in self.predecessors(name):
                    if not any(
                        fn_type in pred_fn
                        for fn_type in ("condition", "decision")
                    ):
                        for pred_var in self.predecessors(pred_fn):
                            G.add_node(
                                self.nodes[pred_var]["basename"],
                                **self.nodes[pred_var],
                            )
                            G.add_node(attrs["basename"], **attrs)
                            G.add_edge(
                                self.nodes[pred_var]["basename"],
                                attrs["basename"],
                            )
                if attrs["is_loop_index"]:
                    G.add_edge(attrs["basename"], attrs["basename"])

        return G