### Start Notepad and Send Text Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/mastering_vba_for_microsoft_office.md This example demonstrates starting Notepad using the Shell command and then using SendKeys to type text into it. The 'True' argument for SendKeys waits for the application to process the keystrokes. ```VBA Sub SendKeysToNotepad() Dim RetVal RetVal = Shell("notepad.exe", vbNormalFocus) SendKeys "Hello World!", True End Sub ``` -------------------------------- ### Install KAG and OpenSPG Backend Source: https://context7.com/openspg/kag/llms.txt Steps to set up a conda environment, clone the KAG repository, install dependencies, and start the OpenSPG backend using Docker Compose. ```bash # Create conda env conda create -n kag-demo python=3.10 && conda activate kag-demo # Clone and install git clone https://github.com/OpenSPG/KAG.git cd KAG && pip install -e . # Start the OpenSPG backend (required) curl -sSL https://raw.githubusercontent.com/OpenSPG/openspg/refs/heads/master/dev/release/docker-compose-west.yml \ -o docker-compose-west.yml docker compose -f docker-compose-west.yml up -d # UI available at http://127.0.0.1:8887 (user: openspg / openspg@kag) ``` -------------------------------- ### Run SparkPi Example in Local Mode Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/machine_learning_with_spark.md Test your Spark setup by running the SparkPi example in local mode. This is useful for verifying Spark installation before cluster testing. ```bash cd spark MASTER=local[2] ./bin/run-example SparkPi ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/google_web_search_mcp/README.md Change your current directory to the google_web_search_mcp example folder. This is the first step before configuring or running the example. ```bash cd kag/examples/google_web_search_mcp ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/open_benchmark/2wiki/README.md Change the current directory to the 2wiki example folder within the KAG project. ```bash cd kag/open_benchmark/2wiki ``` -------------------------------- ### Install and Load R Packages Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/modern_optimization_with_r.md Install packages using install.packages() and load them into the current session using library(). For example, to use the 'pso' package, first install it, then load it, and then access its help. ```R > install.packages("pso") ``` ```R > library(pso) ``` ```R > ?pso ``` -------------------------------- ### Spark Application Setup Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/machine_learning_with_spark.md This code snippet demonstrates how to initialize a Spark application with a specific name and master configuration, and create a SparkContext. Ensure Spark is installed and configured. ```Scala val conf = new SparkConf() .setAppName("Test Spark App") .setMaster("local[4]") val sc = new SparkContext(conf) ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/medicine/README.md Change the current directory to the medicine example folder. ```bash cd kag/examples/medicine ``` -------------------------------- ### Navigate to KAG Examples Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/README.md Change the current directory to the KAG examples folder. This is a prerequisite for running other examples. ```bash cd kag/examples ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/README.md Change the current directory to the CSQA example directory within the KAG project. ```bash cd kag/examples/csqa ``` -------------------------------- ### Navigate to Supply Chain Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/supplychain/README.md Change the current directory to the supply chain example folder. ```bash cd kag/examples/supplychain ``` -------------------------------- ### Demonstrating Transaction Control Commands in SQL Server Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/professional_microsoft_sql_server_programming.md This example demonstrates the use of BEGIN TRAN, INSERT, SAVE TRAN, and ROLLBACK TRAN. It shows how to create a table, start a transaction, insert data, create a savepoint, insert more data, and then roll back to the savepoint, illustrating data persistence and loss. ```sql USE AdventureWorks2008; -- Create table to work with CREATE TABLE MyTranTest ( OrderID INT PRIMARY KEY IDENTITY ); -- Start the transaction BEGIN TRAN TranStart; -- Insert our first piece of data using default values. -- Consider this record No1. It is also the 1st record that stays -- after all the rollbacks are done. INSERT INTO MyTranTest DEFAULT VALUES; -- Create a "Bookmark" to come back to later if need be SAVE TRAN FirstPoint; -- Insert some more default data (this one will disappear -- after the rollback). -- Consider this record No2. INSERT INTO MyTranTest DEFAULT VALUES; -- Roll back to the first savepoint. Anything up to that -- point will still be part of the transaction. Anything -- beyond is now toast. ``` -------------------------------- ### Start PPPoE Server Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/linux_kernel_networking.md Use this command to start a PPPoE server. Specify the interface, local IP, starting remote IP, and maximum concurrent sessions. ```bash pppoe-server -I p3p1 -R 192.168.3.101 -L 192.168.3.210 -N 200 ``` -------------------------------- ### Install KAG for Windows Developers Source: https://github.com/openspg/kag/blob/master/README.md Instructions for Windows developers to install Python and Git, create and activate a virtual environment, clone the KAG repository, and install KAG in editable mode. ```bash # Install the official Python 3.10 or later, install Git. # Create and activate Python venv: py -m venv kag-demo && kag-demo\Scripts\activate # Clone code: git clone https://github.com/OpenSPG/KAG.git # Install KAG: cd KAG && pip install -e . ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/NetOperatorQA/README_en.md Change the current directory to the NetOperatorQA example folder within the KAG project. ```bash cd kag/examples/NetOperatorQA ``` -------------------------------- ### Get Symmetric Key GUID by Name Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/professional_microsoft_sql_server_programming.md Fetches the GUID for a symmetric key given its name in the current database. ```sql Key_GUID('') ``` -------------------------------- ### VBA Property Get Procedure Example Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/mastering_vba_for_microsoft_office.md Use a Property Get procedure to return a value from a property. This example creates a 'Title' property that returns the value of the 'bookTitle' variable. It can be paired with a Property Let to create a read/write property. ```VBA Property Get Title() As String Title = bookTitle End Property ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/baike/README.md Change the current directory to the BaiKe example directory within the KAG project. ```bash cd kag/examples/baike ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/baidu_map_mcp/README.md Change the current directory to the Baidu Map MCP example folder within the KAG project. ```bash cd kag/examples/baidu_map_mcp ``` -------------------------------- ### Perl Version Information Example Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/introducing_regular_expressions.md This is an example of the output you might receive when checking for Perl installation. It shows the Perl version and copyright information. ```text This is perl 5, version 16, subversion 0 (v5.16.0) built for darwin-2level Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. ``` -------------------------------- ### Get Weekday Name in VBA Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/mastering_vba_for_microsoft_office.md Returns the name of the weekday for a given date. This example shows how to get the name for April Fool's Day 2013. ```VBA WeekdayName(Weekday (#4/1/2013#)) ``` -------------------------------- ### Match a word with specific start, end, and length Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/introducing_regular_expressions.md Combine word boundaries (\b), specific characters, and quantifiers to match words with a defined structure. This example matches a word starting with 'A', ending with 'T', and having five characters in between. ```regex \bA.{5}T\b ``` -------------------------------- ### Experimental Setup for Optimization Methods Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/modern_optimization_with_r.md Sets up and runs an experiment to compare optimization methods. It initializes parameters, defines methods, and iterates through runs, applying different optimization strategies and termination criteria. ```R # experiment: ---------------------------------------------- MAXFN=5000 Runs=50; D=5; LP=50; maxit=100 lower=rep(1,D);upper=rep(1000,D) Methods=c("Death","Repair") setMethod("edaTerminate","EDA",edaTerminateMaxGen) GCEDA=CEDA(copula="normal",margin="norm",popSize=LP, maxGen=maxit,fEvalStdDev=10) GCEDA@name="GCEDA" RES=vector("list",length(Methods)) # all results VAL=matrix(nrow=Runs,ncol=length(Methods)) # best values for(m in 1:length(Methods)) # initialize RES object RES[[m]]=matrix(nrow=MAXFN,ncol=Runs) for(R in 1:Runs) # cycle all runs { B=NA;EV=0; F=rep(NA,MAXFN); BEST= -Inf # reset vars. setMethod("edaOptimize","EDA",edaOptimizeDisabled) setMethod("edaTerminate","EDA",edaTerminateMaxGen) suppressWarnings(edaRun(GCEDA,cprofit2,lower,upper)) RES[[1]][,R]=F # store all best values VAL[R,1]=F[MAXFN] # store best value at MAXFN B=NA;EV=0; F=rep(NA,MAXFN); BEST= -Inf # reset vars. # set local repair search method: setMethod("edaOptimize","EDA",localRepair) # set additional termination criterion: setMethod("edaTerminate","EDA", edaTerminateCombined(edaTerminateMaxGen,edaTerminateEvalStdDev)) # this edaRun might produces warnings or errors: suppressWarnings(try(edaRun(GCEDA,cprofit2,lower,upper),silent=TRUE)) if(EV') ``` -------------------------------- ### Match Entire Line with Anchors and Wildcards Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/introducing_regular_expressions.md Combine start and end anchors with wildcards to match an entire line. The dot (.) needs to be escaped (\.) to match a literal dot. This example matches lines starting with 'How' and ending with a literal dot. ```regex ^How.*Country\.$ ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/riskmining/README.md Change the current directory to the risk mining example folder within the KAG project. ```bash cd kag/examples/riskmining ``` -------------------------------- ### Navigate to DomainKG Example Directory Source: https://github.com/openspg/kag/blob/master/kag/examples/domain_kg/README.md Change the current directory to the domain_kg example folder within the KAG project. ```bash cd kag/examples/domain_kg ``` -------------------------------- ### Spark Streaming Application Output Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/machine_learning_with_spark.md Example log output from a running Spark Streaming application, indicating receiver initialization and job starting. ```log ... 14/11/15 21:02:23 INFO scheduler.ReceiverTracker: ReceiverTracker started 14/11/15 21:02:23 INFO dstream.ForEachDStream: metadataCleanupDelay = -1 14/11/15 21:02:23 INFO dstream.SocketInputDStream: metadataCleanupDelay = -1 14/11/15 21:02:23 INFO dstream.SocketInputDStream: Slide time = 10000 ms 14/11/15 21:02:23 INFO dstream.SocketInputDStream: Storage level = StorageLevel(false, false, false, false, 1) 14/11/15 21:02:23 INFO dstream.SocketInputDStream: Checkpoint interval = null 14/11/15 21:02:23 INFO dstream.SocketInputDStream: Remember duration = 10000 ms 14/11/15 21:02:23 INFO dstream.SocketInputDStream: Initialized and validated org.apache.spark.streaming.dstream.SocketInputDStream@ff3436d 14/11/15 21:02:23 INFO dstream.ForEachDStream: Slide time = 10000 ms 14/11/15 21:02:23 INFO dstream.ForEachDStream: Storage level = StorageLevel(false, false, false, false, 1) 14/11/15 21:02:23 INFO dstream.ForEachDStream: Checkpoint interval = null 14/11/15 21:02:23 INFO dstream.ForEachDStream: Remember duration = 10000 ms 14/11/15 21:02:23 INFO dstream.ForEachDStream: Initialized and validated org.apache.spark.streaming.dstream.ForEachDStream@5a10b6e8 14/11/15 21:02:23 INFO scheduler.ReceiverTracker: Starting 1 receivers 14/11/15 21:02:23 INFO spark.SparkContext: Starting job: runJob at ReceiverTracker.scala:275 ... ``` -------------------------------- ### Create Database and Table Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/professional_microsoft_sql_server_programming.md Demonstrates the initial steps of creating a database and a table. Note that without explicit batch separation, subsequent commands might not execute in the intended database context. ```sql CREATE DATABASE Test; CREATE TABLE TestTable ( col1 int, col2 int ); ``` -------------------------------- ### Create a New Project Source: https://github.com/openspg/kag/blob/master/kag/examples/README.md Use this command to create a new knowledge base project in product mode. Ensure you have a valid configuration file. ```bash knext project create --config_path ./example_config.yaml ``` -------------------------------- ### Fix an Invalid Variable Name in VBA Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/mastering_vba_for_microsoft_office.md Variable names cannot start with a digit or contain special characters like exclamation points. This example shows how to correct an invalid name. ```VBA Dim Turn as Integer ``` -------------------------------- ### R Example: Sum of Bits Task with Hill Climbing Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/modern_optimization_with_r.md This R code demonstrates a hill climbing search for the sum of bits task. It first loads the hill climbing functions from 'hill.R' and defines an evaluation function 'sumbin'. The example then sets up parameters to run the search, starting from an all-zero solution. This illustrates a practical application of the implemented algorithm. ```R source("hill.R") # load the hill climbing methods # sum a raw binary object x (evaluation function): sumbin=function(x) sum(x) # Example usage (assuming control, lower, upper, and initial par are defined): # control=list(maxit=10, REPORT=1) # lower=rep(0, 10) # upper=rep(1, 10) # par=rep(0, 10) # hclimbing(par=par, fn=sumbin, change=hchange, lower=lower, upper=upper, control=control, dist=rnorm, mean=0, sd=0.1, round=TRUE, type="max") ``` -------------------------------- ### Create and Save a New Outlook Task Source: https://github.com/openspg/kag/blob/master/kag/examples/csqa/builder/data/mastering_vba_for_microsoft_office.md Use the CreateItem method to create a new task and the Save method to store it. This example sets the subject, start date, due date, and disables the reminder. ```VBA Dim myTask As TaskItem Set myTask = Application.CreateItem(ItemType:=olTaskItem) With myTask .Subject = "Arrange Review Meeting" .StartDate = Date .DueDate = Date + 7 .ReminderSet = False .Save End With ```