### Install Mangle Go Interpreter Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/installing.md Installs the Mangle Go interpreter to a specified directory using the `go install` command. Requires Go programming language to be installed. ```bash GOBIN=~/bin go install github.com/google/mangle/interpreter/mg@latest ``` -------------------------------- ### Mangle Name Syntax Examples Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Illustrates the syntax for Mangle names, which represent entities and are structured with parts starting with '/'. It covers simple and complex name structures. ```mangle /a /test12 /antigone /crates.io/fnv /home.cern/news/news/computing/30-years-free-and-open-web ``` -------------------------------- ### Start Mangle Interactive Interpreter Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Starts the Mangle interactive interpreter. This is the basic command to launch the tool for experimenting with Mangle sources. ```bash go run interpreter/main/main.go ``` -------------------------------- ### Build Mangle Go Implementation from Source Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/installing.md Builds the Mangle Go implementation from source. This involves cloning the repository, navigating to the directory, fetching dependencies, building the project, and running tests. ```bash git clone https://github.com/google/mangle cd mangle go get -t ./... go build ./... go test ./... ``` -------------------------------- ### Preload Mangle Sources on Startup Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Starts the Mangle interactive interpreter and preloads a comma-separated list of Mangle source files. These sources are analyzed as a single atomic set of definitions. ```bash # Example: Preloading two files 'file1.mg' and 'file2.mg'. go run interpreter/main/main.go --load=file1.mg,file2.mg ``` -------------------------------- ### Set up Python Virtual Environment for Mangle Docs Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/README.md This snippet demonstrates setting up a Python virtual environment to manage dependencies for building Mangle documentation. It installs Sphinx and project-specific requirements. ```bash > python -m venv manglereadthedocs > . manglereadthedocs/bin/activate (manglereadthedocs) > pip install -U sphinx (manglereadthedocs) > READTHEDOCS= (manglereadthedocs) > pip install -r ${READTHEDOCS}/requirements.txt ``` -------------------------------- ### Teacher-Learner Session Match Query (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md An Mangle query to find teacher-learner matches considering compatible time slots on a preferred day. ```Mangle teacher_learner_match_session(Teacher, Learner, Skill, PreferredDay, Slot) :- teacher_learner_match(Teacher, Learner, Skill), volunteer_time_available(Teacher, PreferredDay, Slot), volunteer_time_available(Learner, PreferredDay, Slot). ``` -------------------------------- ### Mangle Rules for Data View Switching Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md These Mangle rules illustrate how to transition between different data representations. The first rule defines a 'volunteer' relation from 'volunteer_record' using field matching, retrieving only the ID. The second rule defines 'volunteer_name' to get both ID and Name from the record. ```Mangle volunteer(Id) :- volunteer_record(R), :match_field(R, /id, Id). volunteer_name(Id, Name) :- volunteer_record(R), :match_field(R, /id, Id), :match_field(R, /name, Name). ``` -------------------------------- ### Start Mangle Interpreter with Custom Root Directory Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Starts the Mangle interactive interpreter, specifying a custom root directory for loading files. This flag is useful when your Mangle source files are not in the current working directory. ```bash go run interpreter/main/main.go --root=$PWD/examples ``` -------------------------------- ### Teacher-Learner Match Query (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md An Mangle query to find pairs of volunteers (Teacher, Learner) who share a common skill. ```Mangle teacher_learner_match(Teacher, Learner, Skill) :- volunteer_skill(Teacher, Skill), volunteer_interest(Learner, Skill). ``` -------------------------------- ### Define Volunteer Data (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md Defines a volunteer database using extensional predicates in Mangle. It lists facts about volunteers, their availability, skills, and interests. ```Mangle # We shall use constant symbols like /v/{number} as identifiers. volunteer(/v/1). # Volunteer has a name, some timeslots where they might be available for # volunteering work, some interests and some skills. volunteer_name(/v/1, "Aisha Salehi"). volunteer_time_available(/v/1, /monday, /afternoon). volunteer_time_available(/v/1, /monday, /morning). volunteer_interest(/v/1, /skill/frontline). volunteer_skill(/v/1, /skill/admin). volunteer_skill(/v/1, /skill/facilitate). volunteer_skill(/v/1, /skill/teaching). volunteer(/v/2). volunteer_name(/v/2, "Xin Watson"). volunteer_time_available(/v/2, /monday, /afternoon). volunteer_interest(/v/2, /skill/facilitate). ``` -------------------------------- ### Singleton Type Definition Example Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/typeexpressions.md Shows the syntax for defining a singleton type for a given name using the fn:Singleton constructor. ```Mangle fn:Singleton(/foo) ``` -------------------------------- ### Mangle Byte String Examples Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Illustrates Mangle's byte string literals, indicated by a 'b' prefix. It shows examples with UTF-8 encoded characters and byte sequences, including special characters and multi-byte UTF-8 representations. ```mangle b"A \x80 byte carries special meaning in UTF8 encoded strings" b"\x80\x81\x82\n" b"\xf0\x9f\x98\xa4" ``` -------------------------------- ### Type Variables and Constructed Types Example Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/typeexpressions.md Illustrates type expressions containing type variables (starting with a capital letter) and constructed types using the fn:Pair constructor with basic types. ```Mangle X fn:Pair(Y, /string) ``` -------------------------------- ### Mangle Floating-Point Number Examples Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Shows examples of floating-point numbers in Mangle, represented as 64-bit floating-point values. Includes positive and negative decimal numbers. ```mangle 3.141592 -10.5 ``` -------------------------------- ### Build Mangle Rust Implementation from Source Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/installing.md Builds the Mangle Rust implementation from source using Cargo. This includes cloning the repository, navigating to the Rust directory, building the project, and running tests. Note: The Rust implementation currently lacks an interactive interpreter. ```bash git clone https://github.com/google/mangle cd mangle/rust cargo build cargo test ``` -------------------------------- ### Example of Invalid Data Constraint (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md Demonstrates an example in Mangle where a violation of a data declaration (using an invalid constant) would result in an error. ```Mangle volunteer_interest(/v/1, /monday). # This does not look right. ``` -------------------------------- ### Mangle Predicate Declaration and Usage Example Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Demonstrates how to declare predicates and define rules in the Mangle interactive interpreter. It shows the process of defining a predicate, adding a rule that uses it, and querying the result. ```mangle Decl foo(Arg1, Arg2). mg >Decl foo(X,Y). defined [foo(A, B)]. mg >bar(X) :- foo(X, _). defined [foo(A, B) bar(A)]. mg >foo(1,1). defined [foo(A, B) bar(A)]. mg >?bar bar(1) Found 1 entries for bar. ``` -------------------------------- ### Mangle Integer Number Examples Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Demonstrates the representation of integer numbers in Mangle, which are 64-bit signed integers. Examples show positive, negative, and zero values. ```mangle 0 1 128 -10000 ``` -------------------------------- ### Union Types Examples Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/typeexpressions.md Demonstrates the creation of union types using the fn:Union constructor, including an empty union type and unions with basic and singleton types. ```Mangle fn:Union() fn:Union(/name, /string) fn:Union(fn:Singleton(/foo), fn:Singleton(/bar)) ``` -------------------------------- ### Datalog Facts for Volunteers Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md Represents volunteer data, including their ID, Name, and specific Skills. Each skill is represented as a separate fact. ```datalog volunteer(1, "Aisha Salehi", /teaching). volunteer(1, "Aisha Salehi", /workshop_facilitation). volunteer(2, "Xin Watson", /workshop_facilitation). volunteer(3, "Alyssa P. Hacker", /software_development). volunteer(3, "Alyssa P. Hacker", /workshop_facilitation). ``` -------------------------------- ### Example Fact with List of Structs in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Presents a concrete Datalog fact that includes a list containing three struct constants, each representing a 2D point with x and y coordinates. ```Datalog triangle_2d([ { /x: 1, /y: 2 }, { /x: 5, /y: 10 }, { /x: 12, /y: 5 } ]) ``` -------------------------------- ### Mangle Multi-line String Example Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Demonstrates how Mangle supports multi-line strings using backticks, allowing for the inclusion of newlines and other characters without explicit escape sequences. ```mangle ` I write, erase, rewrite Erase again, and then A poppy blooms. ` ``` -------------------------------- ### Declare Skill Vocabulary (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md Declares a vocabulary of skills as unary predicates in Mangle. These can be used for data validation. ```Mangle skill(/skill/admin). skill(/skill/facilitate). skill(/skill/frontline). skill(/skill/speaking). skill(/skill/teaching). skill(/skill/recruiting). skill(/skill/workshop_facilitation). ``` -------------------------------- ### Mangle Value Table Representation Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md This code snippet demonstrates how to represent data using Mangle's value tables. It shows the structure for a 'volunteer_record' with various fields, including structured types like lists and pairs. This approach is useful for well-defined schemas. ```Mangle volunteer_record({ /id: /v/1, /name: "Aisha Salehi", /time_available: [ fn:pair(/monday, /morning), fn:pair(/monday, /afternoon) ], /interest: [ /skill/frontline ], /skill: [ /skill/admin, /skill/facilitate, /skill/teaching ] }). volunteer_record({ /id: /v/2, /name: "Xin Watson", /time_available: [ fn:pair(/monday, /afternoon) ], /interest: [ /skill/frontline ], /skill: [ /skill/admin, /skill/facilitate, /skill/teaching ] }). ``` -------------------------------- ### Datalog Facts for Acquaintances Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md Establishes direct 'knows' relationships between individuals. These facts serve as the base for defining reachability. ```datalog knows("Aisha", "Xin"). knows("Xin", "Alyssa"). knows("Alyssa", "Selin"). ``` -------------------------------- ### Datalog Rectification Example - Knows Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Demonstrates how a datalog rule with a repeated variable in the head is 'rectified' by introducing a new variable and an equality constraint. This normalized form is then easier to translate into relational algebra. ```datalog knows(X, X) :- person(X). ``` ```datalog knows(X, Y) :- person(X), Y = X. ``` -------------------------------- ### Constrain Argument Position with Declarations (Mangle) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_db.md Uses Mangle declarations to constrain the valid constants for argument positions in predicates, ensuring data integrity. ```Mangle Decl volunteer_interest(Volunteer, Skill) bound [ /v, /skill ]. Decl volunteer_skill(Volunteer, Skill) bound [ /v, /skill ]. ``` -------------------------------- ### Defining Datalog Facts Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md This code snippet demonstrates the basic syntax for defining facts in Datalog. Each fact represents a record in a database table, with the predicate name corresponding to the table name and arguments representing column values. ```datalog volunteer(1, "Aisha Salehi", /teaching). volunteer(2, "Xin Watson", /workshop_facilitation). volunteer(3, "Alyssa P. Hacker", /software_development). ``` -------------------------------- ### Mangle Aggregation Rule for Counting Vulnerable Projects Source: https://github.com/shaleynikov/mangle/blob/main/README.md An example of Mangle's aggregation capabilities, counting projects identified by the `projects_with_vulnerable_log4j` rule. It uses function piping (`|>`) for grouping and counting. ```Mangle count_projects_with_vulnerable_log4j(Num) :- projects_with_vulnerable_log4j(P) |> do fn:group_by(), let Num = fn:Count(). ``` -------------------------------- ### Datalog Rule for Teacher and Coder Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md Identifies individuals who possess both teaching and software development skills. This rule demonstrates conjunction (AND) by requiring both conditions to be met. ```datalog teacher_and_coder(ID, Name) <- volunteer(ID, Name, /teaching), volunteer(ID, Name, /software_development). ``` -------------------------------- ### Datalog Rules for Coding Workshop Candidates Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md Defines rules to identify candidates for a coding workshop based on specific skills like teaching or software development. It uses disjunction (OR) by having separate rules for each skill. ```datalog coding_workshop_candidate(ID, Name, /teaching) <- volunteer(ID, Name, /teaching). coding_workshop_candidate(ID, Name, /software_development) <- volunteer(ID, Name, /software_development). ``` -------------------------------- ### Datalog Rule for Inferring Teachers Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md This Datalog rule infers new facts by defining a 'teacher' predicate based on the 'volunteer' facts. It identifies volunteers who have the '/teaching' skill, extracting their ID and Name. ```datalog teacher(ID, Name) ⟸ volunteer(ID, Name, /teaching). ``` -------------------------------- ### Datalog Recursive Rules for Reachability Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/datalog.md Defines a transitive relationship 'reachable' based on the 'knows' facts. It includes a base case and a recursive step to follow chains of acquaintances. ```datalog reachable(X, Y) <- knows(X, Y). reachable(X, Z) <- knows(X, Y), reachable(Y, Z). ``` -------------------------------- ### Mangle Datalog Family Facts and Sibling Rule Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/index.md Defines parent facts for a family tree and a rule to determine siblings. This example demonstrates basic fact assertion and rule definition in Mangle Datalog. ```cplint parent(/oedipus, /antigone). parent(/oedipus, /ismene). parent(/oedipus, /eteocles). parent(/oedipus, /polynices). sibling(Person1, Person2) <- parent(P, Person1), parent(P, Person2), Person1 != Person2. ``` -------------------------------- ### Datalog Reachable Paths Example in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/rust/README.md This code snippet demonstrates the definition of reachable paths in a graph using Datalog syntax within the Mangle language. It defines a 'reachable' relation based on an 'edge' relation, showcasing recursive rule definition. ```datalog reachable(X, Y) :- edge(X, Y). reachable(X, Z) :- edge(X, Y), reachable(Y, Z). ``` -------------------------------- ### Mangle String Literals and Escapes Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/basictypes.md Provides examples of Mangle string literals, including usage of single quotes, double quotes, and various escape sequences for special characters like quotes, newlines, tabs, and Unicode characters. ```mangle "foo" 'foo' "something 'quoted'" 'something "quoted"' "something \"quoted\" with escapes." 'A single quote \' surrounded by single quotes' "A single quote \' surrounded by double quotes" "A double quote \" surrounded by double quotes" "A newline \n" "A tab \t" "Java class files start with \xca\xfe\xba\xbe" "The \u{01f624} emoji was originally called 'Face with Look of Triumph'" ``` -------------------------------- ### Set up ANTLR and Regenerate Go Parser Sources Source: https://github.com/shaleynikov/mangle/blob/main/README.md This snippet demonstrates how to download the ANTLR library, set up an alias for it, and then use the ANTLR command-line tool to generate Go parser sources from a grammar file. ```bash wget http://www.antlr.org/download/antlr-4.13.2-complete.jar alias antlr='java -jar $PWD/antlr-4.13.2-complete.jar' antlr -Dlanguage=Go -package gen -o ./ parse/gen/Mangle.g4 -visitor ``` -------------------------------- ### Go Build and Test Commands Source: https://github.com/shaleynikov/mangle/blob/main/README.md Provides the essential Go commands for managing dependencies, building the Mangle library, and running its test suite. These commands are standard for Go projects. ```Shell go get -t ./... go build ./... go test ./... ``` -------------------------------- ### Build Mangle Documentation with Sphinx Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/README.md This code snippet shows how to build the Mangle documentation in HTML format using Sphinx. It assumes a virtual environment is already activated and the READTHEDOCS environment variable is set. ```bash > . manglereadthedocs/bin/activate (manglereadthedocs) > READTHEDOCS= (manglereadthedocs) > sphinx-build -M html ${READTHEDOCS} output ``` -------------------------------- ### Simple Mangle Queries for Volunteer Data Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Demonstrates basic Mangle queries to find volunteers based on availability and skills. These queries assume a known knowledge base schema and are designed as one-liners. ```mangle ?volunteer_time_available(VolunteerID, /tuesday, /afternoon) ``` ```mangle ?volunteer_skill(VolunteerID, /skill/workshop_facilitation) ``` -------------------------------- ### Volunteer Query API (gRPC) Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md This section details the gRPC service definition for querying volunteers based on their availability. It includes the request and reply messages, as well as the service method. ```APIDOC ## Volunteer Query API ### Description This API allows clients to query for volunteers by specifying their availability. The service uses gRPC for communication and maps requests to Mangle queries. ### Service VolunteerQuery ### Methods #### GetByMatchingAvailability ##### Description Retrieves a list of volunteers matching the specified availability. ##### Request Type ByAvRequest - **availability** (Availability[]) - Repeated field containing availability information. ##### Response Type ByAvReply - **reply** (Volunteer[]) - Repeated field containing volunteer information. ### Request Example ```protobuf message ByAvRequest { repeated Availability availability = 1; } ``` ### Response Example ```protobuf message ByAvReply { repeated Volunteer reply = 1; } ``` ``` -------------------------------- ### Mangle Query with Datalog Program for Availability Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Shows how to use a Mangle datalog program to combine multiple conditions for finding volunteers with specific availability slots and retrieve their names. The program defines 'good_time' and a 'matching_availability' rule. ```mangle program: """ good_time(/tuesday, /afternoon). good_time(/wednesday, /morning). matching_availability(VolunteerID, Name, Weekday, Timeslot) :- volunteer_time_available(VolunteerID, Weekday, Timeslot), good_time(Weekday, Timeslot), volunteer_name(VolunteerID, Name). """ input: "matching_availability(VolunteerID, Name, Weekday, Timeslot)" ``` -------------------------------- ### Simple Query Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Execute a simple query against the knowledge base. This returns all matching facts for a given input atom. ```APIDOC ## POST /query ### Description Executes a simple query against the knowledge base, returning all matching facts for a given input atom. ### Method POST ### Endpoint /query ### Parameters #### Request Body - **input** (string) - Required - An atom representing the query. ### Request Example ```json { "input": "?volunteer_time_available(VolunteerID, /tuesday, /afternoon)" } ``` ### Response #### Success Response (200) - **output** (array) - A list of facts that match the input atom. #### Response Example ```json { "output": [ "VolunteerID1", "VolunteerID2" ] } ``` ``` -------------------------------- ### Mangle Query with Structured Data for Availability Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Illustrates querying with structured data in Mangle, specifically using a list of pairs to represent desired time slots. This allows for more flexible querying where internal data structures might differ from the API surface. ```mangle # We can only evaluate this predicate in the context of a query that # binds the GoodTimeSlots argument to a value. matching_availability(VolunteerID, Name, GoodTimeSlots) :- volunteer_time_available(VolunteerID, Weekday, Timeslot), :list:member(fn:pair(Weekday, Timeslot), GoodTimeSlots), volunteer_name(VolunteerID, Name). ``` -------------------------------- ### Datalog Selection Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Defines a Datalog predicate 'p' for selection from a predicate 'q'. 'F*' represents the datalog goals corresponding to the selection conditions. ```datalog p(X...) = q(X...), F* ``` -------------------------------- ### gRPC Service Definition for Mangle API Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Defines the gRPC service 'VolunteerQuery' with an RPC method 'GetByMatchingAvailability'. It specifies the request ('ByAvRequest') and reply ('ByAvReply') message formats, which are used for inter-service communication. ```proto // gRPC service definition message ByAvRequest { repeated Availability availability = 1; } message ByAvReply { repeated Volunteer reply = 1; } service VolunteerQuery { rpc GetByMatchingAvailability (ByAvRequest) returns (ByAvReply) {} } ``` -------------------------------- ### Mangle Interpreter Commands Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Lists the available commands within the Mangle interactive interpreter for managing declarations, clauses, querying predicates, loading files, and managing interpreter state. ```plaintext . adds declaration to interactive buffer . adds package-use declaration to interactive buffer . adds clause to interactive buffer, evaluates. ? looks up predicate name and queries all facts ? queries all facts that match goal ::load pops interactive buffer and loads source file at ::help display this help text ::pop reset state to before interactive defs. or last load command ::show shows information about predicate ::show all shows information about all available predicates quit ``` -------------------------------- ### Advanced Query with Program Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Execute a complex query using a custom Mangle datalog program and an input atom. This allows for joins, unions, and recursive queries. ```APIDOC ## POST /query/program ### Description Executes a complex query using a custom Mangle datalog program and an input atom. This allows for joins, unions, and recursive queries. ### Method POST ### Endpoint /query/program ### Parameters #### Request Body - **program** (string) - Optional - A Mangle datalog program. - **input** (string) - Required - An atom representing the query. ### Request Example ```json { "program": "good_time(/tuesday, /afternoon).\ngood_time(/wednesday, /morning).\nmatching_availability(VolunteerID, Name, Weekday, Timeslot) :- volunteer_time_available(VolunteerID, Weekday, Timeslot), good_time(Weekday, Timeslot), volunteer_name(VolunteerID, Name).", "input": "matching_availability(VolunteerID, Name, Weekday, Timeslot)" } ``` ### Response #### Success Response (200) - **output** (array) - A list of facts or structured data matching the query program and input. #### Response Example ```json { "output": [ { "VolunteerID": "VolunteerID1", "Name": "John Doe", "Weekday": "/tuesday", "Timeslot": "/afternoon" } ] } ``` ``` -------------------------------- ### Query with Multiple Inputs Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Execute a query with a list of input atoms. This returns facts that match at least one of the provided atoms. ```APIDOC ## POST /query/union ### Description Executes a query with a list of input atoms, returning facts that match at least one of the provided atoms. ### Method POST ### Endpoint /query/union ### Parameters #### Request Body - **input** (array) - Required - A list of atoms representing the queries. ### Request Example ```json { "input": [ "?volunteer_time_available(VolunteerID, /tuesday, /afternoon)", "?volunteer_time_available(VolunteerID, /wednesday, /morning)" ] } ``` ### Response #### Success Response (200) - **output** (array) - A list of facts that match at least one of the input atoms. #### Response Example ```json { "output": [ "VolunteerID1", "VolunteerID3", "VolunteerID5" ] } ``` ``` -------------------------------- ### Pair Construction in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Demonstrates the construction of a pair using the 'fn:pair' function symbol in Datalog. This is a fundamental way to create structured data. ```Datalog fn:pair(First, Second) ``` -------------------------------- ### List Construction in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Illustrates the creation of list constants in Datalog using the 'fn:list' function symbol or the 'fn:cons' function for building lists element by element. Lists can also be written using bracket notation. ```Datalog fn:list(value1, ..., valueN) [value1, ..., valueN] fn:cons(value, listValue) ``` -------------------------------- ### Map Construction in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Explains how to construct map constants in Datalog using the 'fn:map' function symbol, which takes key-value pairs. Maps can be conveniently written using brace and colon notation. ```Datalog fn:map(key1, value1, ... keyN, valueN) [ key1 : value1, ..., keyN: valueN ] ``` -------------------------------- ### Datalog Set Difference Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Defines a Datalog predicate 'p' using a rule to represent the set difference between two predicates 'q1' and 'q2'. The '!' symbol denotes negation. ```datalog p(X...) := q1(X...), !q2(X...). ``` -------------------------------- ### Datalog Cartesian Product Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Defines a Datalog predicate 'p' representing the Cartesian product of two predicates 'q1' and 'q2'. It uses distinct variables for the arguments of each predicate. ```datalog p(X..., Y...) :- q1(X...), q2(Y...). ``` -------------------------------- ### Mangle Predicate Mode Declaration Source: https://github.com/shaleynikov/mangle/blob/main/docs/example_volunteer_api.md Demonstrates how to declare the mode and properties of a Mangle predicate, specifying which arguments are inputs and outputs. This is a proposed feature for managing query evaluation and information hiding. ```mangle # GoodTimeSlots must be provided at request time Decl matching_availability(VolunteerID, Name, GoodTimeSlots) descr [mode("+", "+", "-"), public()]. ``` -------------------------------- ### Execute Query with Mangle Interpreter and Exit Source: https://github.com/shaleynikov/mangle/blob/main/docs/using_the_interpreter.md Executes a given query using the Mangle interpreter and then exits. If the query returns at least one result, it prints '#PASS' and exits with code 0; otherwise, it prints '#FAIL' and exits with a non-zero code. ```bash # Example usage: Assume 'my_query' is a valid Mangle query. go run interpreter/main/main.go --exec=my_query ``` -------------------------------- ### Datalog Union Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Defines a Datalog predicate 'p' using two rules to represent the union of two predicates 'q1' and 'q2'. This is a base case for combining relations in Datalog. ```datalog p(X...) :- q1(X...). p(X...) :- q2(X...). ``` -------------------------------- ### Mangle Rules for One or Two Leg Trips Source: https://github.com/shaleynikov/mangle/blob/main/README.md Illustrates Mangle's ability to handle n-ary relations and structured data with rules for finding one or two-leg trips between locations. It shows how to construct lists and perform arithmetic operations. ```Mangle one_or_two_leg_trip(Codes, Start, Destination, Price) :- direct_conn(Code, Start, Destination, Price) |> let Codes = [Code]. one_or_two_leg_trip(Codes, Start, Destination, Price) :- direct_conn(FirstCode, Start, Connecting, FirstLegPrice). direct_conn(SecondCode, Connecting, Destination, SecondLegPrice) |> let Code = [FirstCode, SecondCode], let Price = fn:plus(FirstLegPrice, SecondLegPrice). ``` -------------------------------- ### Mangle: Equality and Inequality Comparisons Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_builtin_operations.md Compares two expressions for equality or inequality. Supports integer constants and date values for ordering. ```Mangle Left = Right Left != Right ``` -------------------------------- ### Mangle: Ordering Comparisons Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_builtin_operations.md Performs less than, less than or equal to, greater than, and greater than or equal to comparisons. Supports integer and date constants. ```Mangle Left < Right Left <= Right Left > Right Left >= Right ``` -------------------------------- ### Mangle: List Pattern Matching (Cons and Nil) Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_builtin_operations.md Matches a list data structure. :match_cons matches a non-empty list into its head and tail, while :match_nil matches an empty list. ```Mangle :match_cons(List, Head, Tail) :match_nil(List) ``` -------------------------------- ### Datalog Projection Rule Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_explain_relational_algebra.md Defines a Datalog predicate 'p' for projection from a predicate 'q'. The '_' symbol indicates columns that are not retained in the resulting predicate. ```datalog p(X...) = q(X..., _...). ``` -------------------------------- ### Mangle Recursive Rule for Jar Containment Source: https://github.com/shaleynikov/mangle/blob/main/README.md Demonstrates recursive rule definition in Mangle to determine if a project contains a specific JAR, either directly or through its dependencies. This illustrates how Mangle handles transitive relationships. ```Mangle contains_jar(P, Name, Version) :- contains_jar_directly(P, Name, Version). contains_jar(P, Name, Version) :- project_depends(P, Q), contains_jar(Q, Name, Version). ``` -------------------------------- ### Tuple Construction in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Shows how to construct fixed-length tuples in Datalog using the 'fn:tuple' function symbol. Tuples are essentially nested pairs for sequences longer than two. ```Datalog fn:tuple(value1, ..., valueN) ``` -------------------------------- ### Mangle Doc Descriptor Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_decls.md A descriptor item that provides documentation for a predicate. It accepts one or more strings, with a recommendation for a single multi-line string. ```Mangle doc("", ... "") ``` -------------------------------- ### Constructing Maps in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/constructedtypes.md Demonstrates how to create map data items, which are key-value mappings. Maps are defined using key:value pairs and support trailing commas. ```Mangle [/a: /foo, /b: /bar] [0: "zero", 1: "one",] [/a: 1,] ``` -------------------------------- ### SQL Equivalent for Log4j Vulnerability Query Source: https://github.com/shaleynikov/mangle/blob/main/README.md Translates the Mangle rule for detecting vulnerable log4j versions into an equivalent SQL query. This demonstrates how the Mangle rule maps to standard relational database operations. ```SQL SELECT projects.id as P FROM projects JOIN contains_jar ON projects.id = contains_jar.project_id WHERE contains_jar.version NOT IN ("2.17.1", "2.12.4", "2.3.2") ``` -------------------------------- ### Struct Construction in Datalog Source: https://github.com/shaleynikov/mangle/blob/main/docs/structured_data.md Details the construction of struct constants in Datalog using the 'fn:struct' function symbol, which maps field names to constants. Structs are represented with brace notation. ```Datalog fn:struct(key1, value1, ... keyN, valueN) { key1 : value1, ..., keyN : valueN } ``` -------------------------------- ### Date Construction in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_datamodel.md Mangle provides built-in functions to construct and manipulate date constants. These functions allow for parsing ISO-8601 strings or creating dates from year, month, and day components. ```mangle fn:date("2023-10-06") fn:date:from_string("2023-10-06") fn:date(2023, 10, 6) fn:date:from_parts(2023, 10, 6) fn:date:to_string(@2023-10-06) ``` -------------------------------- ### Mangle: Date Construction from Parts Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_builtin_operations.md Constructs a Mangle /date value from numeric year, month, and day components. Validates the date's existence. ```Mangle fn:date(Year, Month, Day) fn:date:from_parts(Year, Month, Day) ``` -------------------------------- ### Constructing Pairs in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/constructedtypes.md Demonstrates the syntax for creating pair data items, which combine two data items. Pairs are fundamental for building more complex data structures. ```Mangle fn:pair("web", 2.0) fn:pair("hello", fn:pair("world", "!")) ``` -------------------------------- ### Mangle Uses Declaration Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_decls.md Declares that the current source unit can refer to names from a specified package in Mangle. This enables cross-package name resolution. ```Mangle Uses ! ``` -------------------------------- ### Creating Lists in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/constructedtypes.md Shows the syntax for constructing list data items, which are sequences of elements that can be empty. Lists are ordered collections and support trailing commas. ```Mangle [] # empty list [,] # also empty list [0] # list containing single element 0 [/a, /b, /c] [/a, /b, /c,] ``` -------------------------------- ### Mangle Datalog Query for Siblings Source: https://github.com/shaleynikov/mangle/blob/main/readthedocs/index.md A query to find all siblings of Antigone using the previously defined family facts and sibling rule. It shows how to use variables in queries. ```cplint mg >? sibling(/antigone, X) sibling(/antigone,/eteocles) sibling(/antigone,/ismene) sibling(/antigone,/polynices) Found 3 entries for sibling(/antigone,_). ``` -------------------------------- ### Mangle Argument Descriptor Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_decls.md A descriptor item that describes the purpose of a predicate argument. All arguments must be described, even with an empty string. ```Mangle arg(, "") ``` -------------------------------- ### Structured Data in Mangle Source: https://github.com/shaleynikov/mangle/blob/main/docs/spec_datamodel.md Mangle extends Datalog with functions to create structured data types such as pairs, tuples, lists, maps, and structs. These are represented using specific function prefixes and syntax. ```mangle fn:pair(, ) fn:tuple(, ..., ) [ , ... ] [ : , ... : ] {