OpenLLM-France/wikimedia huggingface dataset:
# XQuery/Compare with XQuery
## Motivation

You want to use XQuery to compare two lists of items and find out how the lists are different

## Methods

We will use a variety of functions that iterate through the lists. For each example we will perform some comparison with the second list.

## Simple iteration and test for missing elements

In this first example, we will use a simple for loop to go through each item on a linear list. We then will check to see if that item is anywhere on the second list (regardless of order). If it is on the second list we will display the item from the first list. If not we will output "missing". This is useful if you want to find out if a local collection is missing files from some remote collection.
Note that the conditional expression:
Tests to see if the $item-text is anywhere in list2. If it occurs anywhere this expression will return true.

## Sample Results

Note that this will not report any items on the second list that are missing from the first list.

## Using Quantified Expressions

This can be rewritten using XQuery quantified expressions. There are two reasons for this. First the XQuery optimizer can frequently run quantified expressions much faster and some people feel they are easier to read. See XQuery/Quantified Expressions for more details.
In this second example the list assignments are the same but we will only display the items from list 1 that are missing from list 2.
This returns:
We are now ready to modularize this missing function so that we can pass any two lists to find missing elements.

## Creating a Missing XQuery Function

Our next step is to create an XQuery function that compare any two lists and returns the items in the second list that are not in the first list.
We can rewrite the output function to use this function:
Note that the order of the lists has been reversed in the second call to the missing function. The second pass looks for items on list2 that are not on list1.
Running this query generates the following output:

## Creating HTML Difference Lists

We can use CSS to style the output of these reports.

## Sample Data

This example uses full words of items to show text highlighting:
The following function uses HTML div and span elements and adds class="missing" to each div that is missing. The CSS file will highlight this background.
We then use the following CSS file to highlight the differences. Each missing element must have class="missing" attribute for the missing element to be highlighted in this report.

## Collation

If the lists are in sorted order, or can be sorted into order, an alternative approach is to recursively collate the two lists. The core algorithm looks like:
With the example above, we can merge two lists.
Execute
The actions on merge will depend on the application and the algorithm can be modified to output only mismatched items on one or other list, and handle matching items appropriately. For example, to display the merged list as HTML, we might modify the algorithm to:
Execute
# XQuery/Basic Search
## Motivation

You want to create a basic HTML search page and search service.

## Method

We will create two files. One is an HTML form and the other is a RESTful search service that takes a single parameter from the URL which is the search query. The search service will search a collection of XML files.
Here is the base path to our test search collection:
/db/test/search
The data to be searched will be in the following collection:
/db/test/search/data
In "Browse Collections" in the Admin interface, create the collection "test"; create the collection "search" under it; lastly, create the collection "data" under "search". Upload the two XML documents listed under "Sample Data" to "data"; upload "search-form.xq" and "search.xq" to "search" (instead of uploading, you can Save to URL, using oXygen, or use the Webstart client).

## Search Form
### /db/test/search/search-form.xq

We will create a basic HTML form that has just one input field for the query.
Note that the action will pass the value from the form to a RESTful service. The only parameter will be "q", the query string.

## Search Service

The following file should be placed in /db/test/search/search.xq

### /db/caldeirao/search/search.xq
## Running your Search

To test your search service from a URL, copy the following into the browser navigation toolbar:
You should see the following result:
To drive this service from a form, click the following link or copy it into your browser navigation toolbar:
# XQuery/Call Graphs
## Motivation

You have many XQuery functions and modules and you want to understand the call relationship between them by generating a graph that shows what functions call each other.

### Sample Single Module Call Graph

The following is a sample of a call graph for a single module.
* you can quickly see what functions don't call other functions and are never called (orphan function).
* Some functions call other functions but are not called by other functions within this module.
* Some function are considered leaf functions since they don't call any functions other than standard XQuery library functions.
* Some functions are called many times by other functions. These are good candidates for utility modules.
* Some functions are only called once. If this is the case you know the impact to functions in this module if it is changed.
* Functions with arrows that point back to themselves are recursive functions
Here is an example of a call graph between modules:

## Background

We can extract the call information of a module using the inspect module
Inspect Module on eXist Site
or if you have installed the documents locally on your desktop or laptop: local eXist doc
The inspect function will return a structure like this:
Which we would like to visualize as a graph like the figure above.

## Challenges

GraphViz is a very mature node layout system with many complex features and a non-XML input format.
* There is little feedback information if there are errors in the GraphViz pipeline. We should use try/catch to get more feedback on errors.
* The Dot language does not accept "dash" (-) or colon (:) characters in IDs. If they appear the transform simply returns no results without error messages. These characters must be removed from the IDs and the "label" attribute must be used to display the value on the nodes.
* It would be ideal to have a single XQuery typeswitch transform that does the conversion to SVG, but accurate placement of nodes in a graph is a complex process.
* There should be some ways to adjust the transform placement such as hints that similar function names be grouped together.
* There should be ways to keep this system portable across XML development tools using XQDoc. This depends on the XQDoc tools exporting the right information.

## References

* source code on GitHub
* wikipedia article on graph drawing
* wikipedia article on Graphviz
* Dot Markup Language format
* note on adding the xqdoc:invoked and xqdoc:ref-variable support to XQDoc
* A Technique for Drawing Directed Graphs by Peter North et. el.
* DAG - A Program that Draws Directed Graphs
# XQuery/Compare two XML files
## Motivation

You want to compare two XML files. If the files are the same you want to return a true and if not you want to return a false. Note if you want to see the differences see the XQuery/XML Differences example.

## Method

We will use the xdiff:compare function that comes built in to eXist. To use this you pass two nodes to the compare function:
xdiff:compare($node1 as node, $node2 as node)

## Sample Source Code

Assume you have two different XML files
The result will be: <syntaxhighlight lang="xml"> <results>
</results> </source >
# A-level Computing/AQA/Paper 1/Theory of computation/Abstraction and automation

Abstraction is the process of filtering out – ignoring - the characteristics of patterns that we don't need in order to concentrate on those that we do. It is also the filtering out of specific details. From this we create a representation (idea) of what we are trying to solve. In computational thinking, when we decompose problems, we then look for patterns among and within the smaller problems that make up the complex problem. What are specific details or characteristics?
In pattern recognition we looked at the problem of having to draw a series of cats.
We noted that all cats have general characteristics, which are common to all cats, eg eyes, a tail, fur, a liking for fish and the ability to make meowing sounds. In addition, each cat has specific characteristics, such as black fur, a long tail, green eyes, a love of salmon, and a loud meow. These details are known as specifics.
In order to draw a basic cat, we do need to know that it has a tail, fur and eyes. These characteristics are relevant. We don't need to know what sound a cat makes or that it likes fish. These characteristics are irrelevant and can be filtered out. We do need to know that a cat has a tail, fur and eyes, but we don't need to know what size and colour these are. These specifics can be filtered out.
From the general characteristics we have (tail, fur, eyes) we can build a basic idea of a cat, ie what a cat basically looks like. Once we know what a cat looks like we can describe how to draw a basic cat. Why is abstraction important? Abstraction allows us to create a general idea of what the problem is and how to solve it. The process instructs us to remove all specific detail, and any patterns that will not help us solve our problem. This helps us form our idea of the problem. This idea is known as a ‘model’.
If we don’t abstract we may end up with the wrong solution to the problem we are trying to solve. With our cat example, if we didn’t abstract we might think that all cats have long tails and short fur. Having abstracted, we know that although cats have tails and fur, not all tails are long and not all fur is short. In this case, abstraction has helped us to form a clearer model of a cat.
Abstraction is the gathering of the general characteristics we need and the filtering out of the details and characteristics that we do not need. A model is a general idea of the problem we are trying to solve.
For example, a model cat would be any cat. Not a specific cat with a long tail and short fur - the model represents all cats. From our model of cats, we can learn what any cat looks like, using the patterns all cats share.
Similarly, when baking a cake, a model cake wouldn’t be a specific cake, like a sponge cake or a fruit cake. Instead, the model would represent all cakes. From this model we can learn how to bake any cake, using the patterns that apply to all cakes.
Once we have a model of our problem, we can then design an algorithm to solve it.
# A-level Computing/AQA/Paper 1/Theory of computation/Automation

Definition:
How a process is performed without human intervention
Ethics:
Case study :
There has been impact on the jobs of people working in car factories.
Ford cars is one company that has effected this by the use of their automated equipment to create their cars, thus decreasing employees hours of work.
Human vs Robots
Repetitive
Fatigue
Avoiding mistakes
Can't adapt easily
1 Why is automation deemed as unethical for the manufacturing industry?
2. Why process are automated?
# A-level Computing/AQA/Paper 1/Theory of computation/Backus-naur form

Backus-Naur Form (also known as Backus Normal Form (BNF) or BNF for short) is a notation technique to express syntax of languages in computing. The expression is put in lists and can be used to see if syntax that is written is valid.

## Structure and Layout
### Symbols

BNF is represented using the following symbols:
The way that these symbols are laid out are as such:
In plain English, the expression above means "The parent expression is defined as the child expression 1 or the child expression 2". This means that to make up the parent expression, it must have a child expression and a child expression is made up of other things.

## Example

In this example, The BNF structure is breaking down the syntax to create
* Backus-Naur Form Breakdown of a Home Address
* <Address> ::= <House Number> <Street Name> <Town Name> <City Name> <Country> <Postcode> | <House Number> <Street Name> <City Name> <Country> <Post Code>
* <Postcode> ::= <Area Code> <Street Code>
* <Area Code> ::= <City Prefix> <digit> | <City Prefix> <digit> <digit>
* <Street Name> ::= <Name> <Street Type>
* <Flat Number> ::= <character> | <digit>
* <House Number> ::= <number> | <digit> <number>
* <number>::= <digit> | <digit> <number>
* <Name> ::= <string>
* <Street Type> ::= <string>
* <City Prefix> ::= <string>
* <Street Code> ::= <string>
* <Town Name> ::= <string>
* <City Name> ::= <string>
* <Country> ::= <string>
* <string> ::= <character> | <character><string>
* <character> ::= A|B|C|D|E|F|G|H|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
* <digit> ::= 0|1|2|3|4|5|6|7|8|9
* An Image to show how the address BNF would be laid out.

## Practice Questions

* Using the BNF from the example above about addresses, state whether each input is a valid input.
* 15 Jubilee Lane Blackpool England FY98 5ER
* Answer:
* NO
* 15 Jubilee Lane Blackpool England FY423 5ER
* Answer:
* NO
* 32 Parkstone Road Syston England Leicester LE7 3ZY
* Answer:
* NO
# A-level Computing/AQA/Paper 1/Theory of computation/Compact set notation

Compact set notation is a useful tool to describe the properties of each element of a set, rather than writing out all elements of a set.
The table below lists all of the necessary symbols for compact set notation.
| Symbol | Meaning |
| x ∈ S | x is an element of S |
| | | such that |
| ∧ | and |
| ∨ | or |
| < | smaller than |
| ≦ | smaller or equal than |
| > | greater than |
| ≧ | greater or equal than |
| A ⊆ B | A is a subset of B |
| A ⊂ B | A is a proper subset of B |
| C = A ∪ B | C is the union of A and B |
| C = A ∩ B | C is the intersection of A and B |
| C = A \ B | C is the difference of A and B |
Example 1:
We might want to describe a set A, which contains all natural numbers greater than 10.
This means that we are interested in a subset of ℕ, such that each of its elements is greater than the value 10.
Using set notation this set can be described as:
A = {x|x ∈ ℕ ∧ x> 10}
Example 2:
This time set A is described as natural numbers, which are multiples of 10. This can be notated as:
A = {10x|x ∈ ℕ}
Example 3:
The elements of set A are all even numbers, up to including 12. Set notation allows us to write this set as {0,2,4,6,8,10,12}, which in this example is feasible.
However, this would be very impractical, if A is described as all even numbers, up to including 1,000,000!
A = {2x | x ∈ N &and 2x ≦ 1,000,000}
The table below explains how each expression is linked to the English description of the elements of the set A.
| English description... | ... expressed in set notation |
| x must be even | 2x |
| such that | 2x | |
| 2x must be a natural number | 2x ∈ N |
| 2x must be smaller or equal than 1,000,000 | 2x ≦ 1,000,000 |
Example 4:
Set A is described as all the natural multiples of 3, below 5,000.
A = {3x | x ∈ N ∧ 3x < 5,000}
The table below explains how each expression is linked to the English description of the elements of the set A.
| English description... | ... expressed in set notation |
| x must be a multiple of 3 | 3x |
| such that | 3x | |
| x must be a natural number | x ∈ N |
| 3x must be smaller than 5,000 | 3x < 5000 |
* Questions
* Using set notation, define the set A as all the numbers divisible by 4. Which of the following terms are applicable to A: countable, uncountable, finite, infinite.
* Answer:
* A = {4x | x ∈ N } Set A is a countably infinite set.

## Programming

Not every programming language offers the ability to perform set theory calculations out of the box. In Visual Basic it has only been available since VB.NET 2008, using the LINQ libraries that you have to import to get it working:
# A-level Computing/AQA/Paper 1/Theory of computation/Decomposition
## Decomposition

This is the first step we take in computational thinking. First, we need to decompose, or break down, the problem into the smaller problems. Then we can solve each problem separately. This will help us to simplify complex problems into each step we should analyse. Let's look at the example of a journey to London.

### Real World Example

Think about taking a trip from Basingstoke to London Waterloo. The steps you take from your house to the train station seem quite complex. But if you break it down to the different stages of the trip, decomposition makes it easier. You need directions, transportation, times and prices for a successful journey. Work backwards from the time you need to be in London which is 12 noon.
1. Make sure you have a paper A-Z London with the tube map.
          (You never know when your mobile may fail to connect to the internet!)
2. Which trains get into London before 12?
          There is a train leaving Basingstoke at 10:57 that arrives at London Waterloo at 11:49.
3. Then think about how you would arrive at the train station. Do you need a bus, car, or can you walk?
          You can walk to the train station and it takes you 10 minutes.
4. Finally, you need to have enough money for your journey and a snack.
          By checking the train website, you find the journey will cost £22.50 return. You make sure you have £30 cash in total.
Now you have all the steps necessary to complete your journey. Decomposition ensures you have enough money, directions, transportation options and timings. You can now apply this method to computing with modular design.
# A-level Computing/AQA/Paper 1/Theory of computation/Classification of algorithms
## Classification of Algorithms

* Comparing Algorithms
* Maths for understanding Big-0 notation
* Order of complexity
* Limits of computation
* Classification of algorithmic problems
* Computable and non-computable problems
* Halting problem
* Turing machine - A model of computation
# A-level Computing/AQA/Paper 1/Theory of computation/Composition

Composition is putting pieces back together the opposite of the decomposition
In computing there are 2 types of composition: (1) Object Composition and (2) Function Composition
Generally speaking, both types of composition involve incorporating multiple objects/functions to create a single, more complex object/function. The process of determining objects/functions to be 'composed' is part of the abstraction process (see computational thinking), and could be the direct result of decomposition (see decomposition). This is a required process of the Software Development Lifecycle, but can be applied to any other activity where Computational Thinking is applied.
The following function could be decomposed:
Function PrintCustomerBankAccounts
into
Function PrintCustomerSavingsAccount
Function PrintCustomerBankAccount
if there were different attributes (see attributes) for the 2 account types.
However it may be determined
# A-level Computing/CIE/Fundamental Problem-solving and Programming skills/Software development

* Specification link
* Programming
* show understanding of how to write, translate, test and run a high-level language program
* show understanding of the basic stages in the program development cycle
* describe features found in a typical Integrated Development Environment (IDE):
* for coding
* for initial error detection
* for debugging, including: single stepping, breakpoints, variables/expressions report window.
* Program testing
* show understanding of ways of exposing faults in programs and ways of avoiding faults
* locate and identify the different types of errors:
* syntax errors
* logic errors
* run-time errors.
* correct identified errors
* Testing strategies
* choose suitable data for black-box testing
* choose suitable data for white-box testing
* understand the need for stub testing
# A-level Computing/CIE/Further Problem Solving and Programming skills/Further programming

* Specification link
* Programming paradigms
* show understanding of what is meant by a programming paradigm
* show understanding of the characteristics of a number of programming paradigms (low-level, imperative, object-oriented, declarative)
* imperative programming – see details in Section 2.3
* low-level programming – demonstrate an ability to write low-level code that uses various address modes: immediate, direct, indirect, indexed and relative (see Section 1.4.3 and Section 3.6.2)
* object-oriented programming (OOP) – demonstrate an ability to solve a problem by designing appropriate classes
* demonstrate an ability to write code that demonstrates the use of classes, inheritance, polymorphism and containment (aggregation)
* declarative programming
* demonstrate an ability to solve a problem by writing appropriate facts and rules based on supplied information
* demonstrate an ability to write code that can satisfy a goal using facts and rules
* File processing
* write code to define a record structure
* write code to perform file-processing operations: open or close a file; read or write a record to a file
* use pseudocode for random file handling:
* OPENFILE <filename> FOR RANDOM
* SEEK <address> // get a pointer to the disk address for the record
* GETRECORD <filename>,<identifier>
* PUTRECORD <filename>,<identifier>
* write code to perform file-processing operations on serial, sequential and random files
* Exception handling
* show understanding of an exception and the importance of exception handling
* show understanding of when it is appropriate to use exception handling
* write code to use exception handling in practical programming
* Use of development tools/programming environments
* describe features in editors that benefit programming
* know when to use compilers and interpreters
* describe facilities available in debuggers and how and when they should be deployed
* show understanding of a range of software development methodologies: waterfall, RapidApplication Development (RAD), Agile
# A-level Computing/CIE/Fundamental Problem-solving and Programming skills

2.1 Algorithm design and problem-solving 2.2 Data representation 2.3 Programming 2.4 Software development
# A-level Computing/CIE/Fundamental Problem-solving and Programming skills/Data representation

* Specification link
* Data types
* select appropriate data types for a problem solution
* use in practical programming the data types that are common to procedural high-level languages: integer, real, char, string, Boolean, date (pseudocode will use the following data types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE, ARRAY, FILE)
* show understanding of how character and string data are represented by software including the ASCII and Unicode character sets
* Arrays
* use the technical terms associated with arrays including upper and lower bound
* select a suitable data structure (1D or 2D array) to use for a given task
* use pseudocode for 1D and 2D arrays (pseudocode will use square brackets to contain the array subscript, for example a 1D array as A[1:n] and a 2D array as C[1:m, 1:n])
* write program code using 1D and 2D arrays
* write algorithms/program code to process array data including:
* sorting using a bubble sort
* searching using a linear search.
* Files
* show understanding of why files are needed
* use pseudocode for file handling:
* OPENFILE <filename> FOR READ/WRITE/APPEND // Open file (understand the difference between various file modes)
* READFILE <filename>,<string> // Read a line of text from the file
* WRITEFILE <filename>,<string> // Write a line of text to the file
* CLOSEFILE // Close file
* EOF // function to test for the end of the file
* write program code for simple file handling of a text file, consisting of several lines of text
* Cambridge International state that using the With command in Python is acceptable.
* (In official newsgroup for teachers)
# A-level Computing/CIE/Computer systems, communications and software/System software/Utility software

Utility software includes programs which perform functions which help operate and maintain a computer system. This includes disk formatters, automated backup software, hardware device drivers, anti-virus software, firewall software and other similar types of software.