<jupyter_start><jupyter_text>CAS Connection<jupyter_code>import swat
s = swat.CAS(host, port)<jupyter_output><empty_output><jupyter_text>Import Helper Functions<jupyter_code>import pandas as pd
import document_classification_scripts as scripts
demo = scripts.Demo(s)<jupyter_output>NOTE: Added action set 'sampling'.
NOTE: Added action set 'pca'.
NOTE: Added action set 'fedsql'.
NOTE: Added action set 'deepLearn'.
NOTE: Added action set 'network'.
NOTE: Added action set 'transpose'.
NOTE: Added action set 'table'.
NOTE: Added action set 'builtins'.
NOTE: Added action set 'neuralNet'.
NOTE: Added action set 'autotune'.
NOTE: Added action set 'session'.
NOTE: Added action set 'decisionTree'.
NOTE: Added action set 'aStore'.
NOTE: Added action set 'aggregation'.<jupyter_text>Example 1 Cycle Enumeration on a Directed GraphCycles are closed pathways through a graph that traverse nodes in the graph no more than once.<jupyter_code>nodes = {
    "node": ["A","B","C","D","E","F"],
} 
nodesDf = pd.DataFrame(nodes, columns = ["node"])
s.upload(nodesDf, casout={"name": "nodes", "replace": True});

links = {
    "from": ["A","A","B","C","C","D","D","E","E","F"],
    "to"  : ["B","E","C","A","D","E","F","B","C","E"]
} 
linksDf = pd.DataFrame(links, columns = ["from", "to"])
s.upload(linksDf, casout={"name": "links", "replace": True});
scripts.graph2dot(linksDf=s.CASTable("links"), nodesDf=s.CASTable("nodes"), layout='circo', directed=True, stdout=False)
s.loadactionset(actionset="network")
s.network.cycle(
    direction      = "directed",
    links          = {"name":"links"},
    nodes          = {"name":"nodes"},
    maxCycles      = "all",
    outCyclesNodes = {"name":"cycleNodes", "replace":True},
    outCyclesLinks = {"name":"cycleLinks", "replace":True});
demo.head("cycleLinks",7)
for i in range(7):
    display(demo.highlightCycle(i))<jupyter_output><empty_output><jupyter_text>Example 2 Centrality of an Undirected GraphCentrality algorithms give a quantitative measurement of how important, influential, or central a given node is to the graph, relative to the other nodes.<jupyter_code>links = {
    "from": ["B","D","D","E","E","E","F","G","G","H","H","I","I","J","K"],
    "to"  : ["C","A","B","B","D","F","B","B","E","B","E","B","E","E","E"]
} 
linksDf = pd.DataFrame(links, columns = ["from", "to"])
s.upload(linksDf, casout={"name": "links", "replace": True});
scripts.graph2dot(linksDf=s.CASTable("links"), stdout=False)<jupyter_output><empty_output><jupyter_text>Compute Closeness and Degree Centrality<jupyter_code>s.network.centrality(
    links     = {"name":"links"},
    close     = "unweight",
    degree    = "unweight",
    outNodes  = {"name":"outCentralityNodes", "replace":True});
demo.head("outCentralityNodes")
scripts.graph2dot(linksDf=s.CASTable("links"),
          nodesDf=s.CASTable("outCentralityNodes"),
          nodesSize="centr_close_unwt",
          nodesSizeScale=2,
          size=10,
          stdout=False
         )
scripts.graph2dot(linksDf=s.CASTable("links"),
          nodesDf=s.CASTable("outCentralityNodes"),
          nodesSize="centr_degree_out",
          nodesSizeScale=1/3.0,
          size=10,
          stdout=False
         )<jupyter_output><empty_output><jupyter_text>Example 3 Load GraphWhat if you wanted to run multiple algorithms against the same graph? It is not ideal to load graph data from CAS tables every time, but this is, in fact, what happens when you specify the graph using the LINKS= and/or NODES= options.A more efficient approach is available via the loadGraph and unloadGraph actions. When using loadGraph, the CAS tables are ingested only once, and in subsequent algorithm calls, you can point to an in-memory graph using the GRAPH= option in lieu of the LINKS= and NODES= options.<jupyter_code>r = s.network.loadGraph(
    links = {"name":"links"},
    )
loadedGraph = r.graph<jupyter_output>NOTE: The number of nodes in the input graph is 11.
NOTE: The number of links in the input graph is 15.<jupyter_text>Next, compute pageRank and degree centrality on the loaded graph.<jupyter_code>s.network.centrality(
    graph     = loadedGraph,
    pageRank  = "unweight",
    degree    = "unweight",
    outNodes  = {"name":"outCentralityNodes", "replace":True});<jupyter_output>NOTE: The number of nodes in the input graph is 11.
NOTE: The number of links in the input graph is 15.
NOTE: Processing centrality metrics.
NOTE: Processing centrality metrics used 0.00 (cpu: 0.00) seconds.<jupyter_text>Now, compute the shortest path from "K" to "C" in the loaded graph.<jupyter_code>s.network.shortestPath(
    graph          = loadedGraph,
    source         = "K",
    sink           = "C",
    outPaths       = {"name":"pathLinks", "replace":True});
demo.highlightPath()<jupyter_output><empty_output><jupyter_text>Cleanup After the in-memory graph is no longer needed, you can free the graph with the unloadGraph action.<jupyter_code>s.network.unloadGraph(
    graph = loadedGraph
);
s.terminate();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15079681274900397, 'fraction_numerical': 0.0061752988047808766, 'mean_word_length': 4.738285714285714, 'pattern_counts': {'":': 23, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '204636', 'license': 'Apache-2.0', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1604, 'n_words': 444, 'path': 'demos/PCT5300-Reese-CoraClassification/python/part_0_network_intro.ipynb', 'repo_name': 'brandonmreese/sas-global-forum-2020', 'size': '5020'}