OpenLLM-France/wikimedia huggingface dataset:
# XQuery/Saving and Updating Data
## Motivation

You have some web forms (such as XForms) that need to save their data to your database. You want a single XQuery that will be used to save new data and update existing data. If a form is used to update an existing record, you can assume that it has an <id> tag in the XML document being saved. New documents will need to have a new document id created for them.

## Method

We use HTTP POST data and scan for a specific element like id. If the record does not have an id element, we know that we must create a new record. Note that there is no sequence number generated in this example yet. If there is an id parameter, we will delete the old file and save the new data into the same file. Note that there is no backup or archive.

## Sample Program to Insert an XML item at the end of an XML file

Sometimes you do not want to create a new XML file, but only save the results at the end of an existing XML file. This can be done using the XQuery update operations.
W3C Candidate Recommendation for XQuery Update Operations
eXist 1.2/1.3/1.4/1.5 syntax for XQuery Update Operations
For example, in eXist 1.2/1.3/1.4 the operation syntax is the following:
# XQuery/Searching multiple collections
## Motivation

You want to find records in multiple collections.

## Method

There are several ways to do this. The simplest way is to put both collections in a parent collection and start your search at the parent.
Lets assume you have three collections:
To get all the books in both collection a and b just specify the parent collection which is /db/test
Note that the double forward slash // will find the books anywhere in the base collection or any child collections.
If you have two collections that are at different locations in a file system you can simply specify each collection and join them together using the sequence join operation. This is the default operation of enclosing two sequences in parenthesis. For example if you have two sequences, a and b, the concatenation of the two sequences is just (a,b).
Assume you have two collections that have books in the following collections:

### Collection A

File='/db/test/a/books.xml'

### Collection B

File='/db/test/b/books.xml'
The following query would operate on both collections.
If you wanted to only return the titles you could use the following:
This would return the following results:
# XQuery/Searching, Paging and Sorting

These examples use a simple XML file containing data on Earthquakes around the world. The data come from Swivel. The examples use the generic table-viewer introduced in "Creating Custom Views" for output.

## Searching

This example searches for a string in the location of the earthquake.
Execute

## Paging

This script implements paging of the search results. Here the full search is repeated for each call, with the state of the interaction held in a hidden input.
Execute

## Sorting

To get the columns sorted, we add a submit button to each column. This requires extending the generic table viewer to sort the nodes by the selected column.
Note that the sort is by string value: Sorting by magnitude succeeds only by chance, whereas the sort on Fatalities does not.
Execute
An improvement would be to allow successive clicks to a column heading to reverse the sort direction. This requires the addition of two more items into the interaction state, the current sort order and current direction, and changes to the table generator. One would like to be able to say something like:
but this is not a valid FLWOR expression. Instead we have to have two FLWOR expressions, one for each direction.
Then the script becomes:
Execute

## Using a table schema

Greater control over the output can be obtained by providing a schema for the table. This schema can specify the order of columns and column headings, and potentially conversion instructions as well.
We can provide the table schema as a sequence of Column definitions:
The schema-based function looks like:
Note the use of a XQuery idiom to compute the column heading as the supplied heading if there is one, otherwise the node name:
This computes the first non-null item in the sequence, a cleaner and more generalisable alternative to:
Execute
# XQuery/Sequences Module
## Motivation

You want to perform a function on a sequence. You can one of the following functions: map, fold or filter.

## Method

Here is the structure of these three functions.
Each of them takes an XQuery function as the first argument.

### Map

The map function applies the function item $f to every item from the sequence $seq in turn, returning the concatenation of the resulting sequences in order.
W3C Page on Map
# XQuery/Setting HTTP Headers
## Motivation

You want to put information in your outgoing HTTP headers to control aspects such as web caching and ETAGS.

## Sample Module

The following module was provided by Thomas White.
File tw_stream-binary-cached.xql
# XQuery/SPARQL interface

The following script provides, via a Joseki server at UWE, a query interface to RDF. Literal language and datatype are ignored in this representation. URIs link to the browse query and also directly to the resource.
A function converts the SPARQL XML Query result to a table, with links.
The SPARQL interface uses the configuration file to declare the namespaces.

## Application

Query
The interface expands a query like
into:
and sends this to the Joseki service. The graph to query is actually passed as the default graph rather than in the from clause.

## To do

* handle language and datatype
* local URIs as local names rather than full URIs#
* better handling of default graph - should be able to reference the cached rdf defined in the config file
# Trigonometry/Addition and Subtraction Theorems

Identities
1. If T$_n$ = sin$^n$ + cos $^n$ Then T$_5$ - T$_1$ = ?
# Trigonometry/Applications and Models
## Simple harmonic motion

Simple harmonic motion (SHM) is the motion of an object which can be modeled by the following function:
    $x=A\sin \left(\omega t+\phi \right)$
or
    $x=c_{1}\cos \left(\omega t\right)+c_{2}\sin \left(\omega t\right)$
    where c$_1$ = A sin φ and c$_2$ = A cos φ.
In the above functions, A is the amplitude of the motion, ω is the angular velocity, and φ is the phase.
The velocity of an object in SHM is
    $v=A\omega \cos \left(\omega t+\phi \right)$
The acceleration is
    $a=-A\omega ^{2}\sin \left(\omega t+\phi \right)=-\omega ^{2}x$
An alternative definition of harmonic motion is motion such that
    $\displaystyle a=-\omega ^{2}x$

### Springs and Hooke's Law

An application of this is the motion of a weight hanging on a spring. The motion of a spring can be modeled approximately by Hooke's law:
    F = -kx
where F is the force the spring exerts, x is the extension in meters of the spring, and k is a constant characterizing the spring's 'stiffness' hence the name 'stiffness constant'.

#### Calculus-based derivation

From Newton's laws we know that F = ma where m is the mass of the weight, and a is its acceleration. Substituting this into Hooke's Law, we get
    ma = -kx
Dividing through by m:
    $a=-{\frac {k}{m}}x$
The calculus definition of acceleration gives us
    $x''=-{\frac {k}{m}}x$
    $x''+{\frac {k}{m}}x=0$
Thus we have a second-order differential equation. Solving it gives us
    $x=c_{1}\cos \left({\sqrt {\frac {k}{m}}}t\right)+c_{2}\sin \left({\sqrt {\frac {k}{m}}}t\right)$ (2)
with an independent variable t for time.
We can change this equation into a simpler form. By letting c$_1$ and c$_2$ be the legs of a right triangle, with angle φ adjacent to c$_2$, we get
    $\sin \phi ={\frac {c_{1}}{\sqrt {c_{1}^{2}+c_{2}^{2}}}}$
    $\cos \phi ={\frac {c_{2}}{\sqrt {c_{1}^{2}+c_{2}^{2}}}}$
and
    $c_{1}={\sqrt {c_{1}^{2}+c_{2}^{2}}}\sin \phi$
    $c_{2}={\sqrt {c_{1}^{2}+c_{2}^{2}}}\cos \phi$
Substituting into (2), we get
    $x={\sqrt {c_{1}^{2}+c_{2}^{2}}}\sin \phi \cos \left({\sqrt {\frac {k}{m}}}t\right)+{\sqrt {c_{1}^{2}+c_{2}^{2}}}\cos \phi \sin \left({\sqrt {\frac {k}{m}}}t\right)$
Using a trigonometric identity, we get:
    $x={\sqrt {c_{1}^{2}+c_{2}^{2}}}\left[\sin \left(\phi +{\sqrt {\frac {k}{m}}}t\right)+\sin \left(\phi -{\sqrt {\frac {k}{m}}}t\right)\right]+{\sqrt {c_{1}^{2}+c_{2}^{2}}}\left[\sin \left({\sqrt {\frac {k}{m}}}t+\phi \right)+\sin \left({\sqrt {\frac {k}{m}}}t-\phi \right)\right]$
    $x={\sqrt {c_{1}^{2}+c_{2}^{2}}}\sin \left({\sqrt {\frac {k}{m}}}t+\phi \right)$ (3)
Let $A={\sqrt {c_{1}^{2}+c_{2}^{2}}}$ and $\omega ^{2}={\frac {k}{m}}$. Substituting this into (3) gives
    $x=A\sin \left(\omega t+\phi \right)$
Next Page: Using Fundamental Identities Previous Page: Inverse Trigonometric Functions
Home: Trigonometry
# Trigonometry/Angles of Elevation and Depression

Suppose you are an observer at $O$ and there is an object $Q$ , not in the same horizontal plane. Let $OP$ be a horizontal line such that $O,P,Q$ are in a vertical plane. Then if $Q$ is above $0$ , the angle $\angle QOP$ is the angle of elevation of $Q$ observed from $P$ , and if $Q$ is below $O$, the angle $\angle QOP$ is the angle of depression.
Often when using angle of elevation and depression we ignore the height of the person, and measure the angle from some convenient 'ground level'.
* Exercise 1: Opposite, Hypotenuse, Adjacent
* Look at the diagram above.
* $\angle MLT$ is a right angle. What would you give as the translation of the labels into English?
* Example 1: A Flagpole
* From a point $10m$ from the base of a flag pole, its top has an angle of elevation of $50^{\circ }$ . Find the height of the pole.
* [diagram]
* If the height is $h$ , then ${\frac {h}{10}}=\tan(50^{\circ })$ . Thus $h=10\tan(50^{\circ })=11.92m$ (to two decimal places).
* Example 2: A $15m$ High Flagpole
* A flag pole is known to be $15m$ high. From what distance will its top have an angle of elevation of $50^{\circ }$ ?
* [diagram]
* If the distance is $d$ , then ${\frac {15}{d}}=\tan(50^{\circ })$ . Thus $d={\frac {15}{\tan(50^{\circ })}}=12.59m$ (to two decimal places).
* Example 3: A $20m$ Tower
* From the foot of a tower $20m$ high, the top of a flagpole has an angle of elevation of $30^{\circ }$ . From the top of the tower, it has an angle of depression of $25^{\circ }$ . Find the height of the flagpole and its distance from the tower.
* Let the height of the flagpole be h and its distance be d. Then
* (i) ${\frac {h}{d}}=\tan(30^{\circ })$
* The top of the flagpole is below the top of the tower, since it has an angle of depression as viewed from the top of the tower. It must be $20-h$ metres lower, so
* (ii) ${\frac {20-h}{d}}=\tan(25^{\circ })$
* Adding these two equations, we find
* (iii) ${\frac {20}{d}}=\tan(30^{\circ })+\tan(25^{\circ })$
* From this (how?) we find $d=19.16m\ ,\ h=11.06m$ (both to two decimal places).
* Example 4: Yet another Flagpole
* From a certain spot, the top of a flagpole has an angle of elevation of $30^{\circ }$ . Move $10m$ in a straight line towards the flagpole. Now the top has an angle of elevation of $50^{\circ }$ . Find the height of the flagpole and its distance from the second point.
* [diagram]
* Let the height be $h$ and its distance from the second point be $x$ . Then
* $\cot(50^{\circ })={\frac {x}{h}}\ ;\ \cot(30^{\circ })={\frac {x+10}{h}}$
* Subtracting the first expression from the second,
* $\cot(30^{\circ })-\cot(50^{\circ })={\frac {10}{h}}$
* $h={\frac {10}{\cot(30^{\circ })-\cot(50^{\circ })}}=11.20m$
* $x=h\cot(50^{\circ })=9.40m$
# Trigonometry/Area of a quadrilateral

Take any quadrilateral ABCD. Write AB=a, BC=b, CD=c, DA=a; σ = $^1$⁄$_2$(a+b+c+d); area of ABCD = S.
Note that a+b+c-d = 2(σ-d) and similarly for the other sides.
The diagonals of ABCD are AC and BD. Let the angle between them be θ. Then S = $^1$⁄$_2$AC.BD.sin(θ).
If ABCD is convex and the diagonals intersect at P, this is easily proved by considering the four triangles ABP, BCP, CDP, DAP since S is the sum of the areas of these four triangles. IF ABCD is not convex, then one of the vertices, say C, must lie inside the triangle ABD. We then find S as the area of ABD less the area of BCD.
Let angle A+C = 2α. To find S in terms of the sides and alpha;.
We can find BD$^2$ by applying the cosine theorem to either of the triangles BAD, BCD. This means that
    a$^2$+d$^2$-2ad.cos(A) = b$^2$+c$^2$-2bc.cos(C)
so
    a$^2$+d$^2$-b$^2$-c$^2$ = 2ad.cos(A)-2bc.cos(C) ... (i)
Also
    S = area(BAD) + area(BCD) = $^1$⁄$_2$ad.sin(A) + $^1$⁄$_2$bc.sin(C)
so
    4S = 2ad.sin(A) + 2bc.sin(C) ... (ii)
Taking (ii)$^2$ + (i)$^2$,
    16S$^2$ + (a$^2$+d$^2$-b$^2$-c$^2$)$^2$ = 4a$^2$d$^2$ + 4b$^2$c$^2$ - 8abcd.cos(A+C)
But
    cos(A+C) = cos(2α) = 2cos$^2$(α)-1
so
    16S$^2$ = 4(ad+bc)$^2$ - (a$^2$+d$^2$-b$^2$-c$^2$)$^2$ - 16abcd.cos$^2$(α).
Simplifying,
    S$^2$ = (σ-a)(σ-b)(σ-c)(σ-d) - abcd.cos$^2$(α).
This expression becomes even simpler for a cyclic quadrilateral, because then cos(α) = 0 so the last term disappears.

## The diagonals and circumradius of a cyclic quadrilateral

In the expression (i) above, for a cyclic quadrilateral cos(C) = -cos(A), so
    $2(ad+bc)\cos(A)=a^{2}+d^{2}-b^{2}-c^{2}$.
From the cosine theorem,
    $BD^{2}=a^{2}+d^{2}-2ad.\cos(A)=a^{2}+d^{2}-{\frac {ad(a^{2}+d^{2}-b^{2}-c^{2})}{ad+bc}}={\frac {(ab+cd)(ac+bd)}{ad+bc}}$.
Similarly,
    $AC^{2}={\frac {(ab+cd)(ad+bc)}{ab+cd}}$.
Thus AC.BD = ac+bd (as we already knew) and
    ${\frac {AC}{BD}}={\frac {ad+bc}{ab+cd)}}$.
The circumcircle of ABCD is also the circumcircle of triangle ABD, so
    $R={\frac {BD}{2\sin(A)}}={\frac {(ad+bc)BD}{2(ad+bc)\sin(A)}}={\frac {(ad+bc)BD}{4S}}={\frac {1}{4S}}{\sqrt {(ab+cd)(ac+bd)(ad+bc)}}$.
    $\tan ^{2}\left({\frac {B}{2}}\right)={\frac {(\sigma -a)(\sigma -b)}{(\sigma -c)(\sigma -d)}}$.

## Further results

If a quadrilateral is circumcyclic, i.e. such that a circle can be inscribed in it touching all four sides, then a+c=b+d. This is easily proved by noting that the lengths of the two tangents from a point to a circle are equal in length.
The radius of the inscribed circle is called the inradius and equals S/σ.
Theorem: If a quadrilateral ABCD is both cyclic and circumcyclic, then
    $\tan ^{2}\left({\frac {A}{2}}\right)={\frac {bc}{ad}}$.
Proof: Since ABCD is cyclic,
    $\cos(A)={\frac {a^{2}+d^{2}-b^{2}-c^{2}}{2(ad+bc)}}$.
Since a+c=b+d, a-d=b-c, i.e. a$^2$+d$^2$-b$^2$-c$^2$ = 2(ad-bc). Thus
    $\cos(A)={\frac {ad-bc}{ad+bc}}$
    $\tan ^{2}\left({\frac {A}{2}}\right)={\frac {1-\cos(A)}{1+\cos(A)}}={\frac {bc}{ad}}$.
If a quadrilateral ABCD is both cyclic and circumcyclic, then its area is √(abcd) and inradius is 2√(abcd)/(a+b+c+d).
# SwisTrack/Components/OutputImageStatisticsColor
## Description

This component calculates and outputs the following statistical values for each channel of a color image:
* Number of non-zero pixels
* Sum of all pixels
* Mean and standard deviation of all pixels
* Minimum and maximum value among all pixels
Combined with (adaptive) background subtraction, such values are useful to detect sudden changes or out-of-the-ordinary frames in a video stream.

## Input

A color image.

## Output

The statistical values are written to the NMEA stream.

## Parameters

Each of the values mentioned above can be enabled or disabled. For performance reasons, it is advisable to enable only those values which are needed.
# SwisTrack/Components/OutputImageStatisticsGray
## Description

This component calculates and outputs the following statistical values of a grayscale image:
* Number of non-zero pixels
* Sum of all pixels
* Mean and standard deviation of all pixels
* Minimum and maximum value among all pixels
Combined with (adaptive) background subtraction, such values are useful to detect sudden changes or out-of-the-ordinary frames in a video stream.

## Input

A grayscale image.

## Output

The statistical values are written to the NMEA stream.

## Parameters

Each of the values mentioned above can be enabled or disabled. For performance reasons, it is advisable to enable only those values which are needed.
# SwisTrack/Components/OutputParticles
## Description

This component writes the particle positions (and other properties) to the NMEA stream.

## Input

A set of particles.

## Output

The particles with their properties are written to the NMEA stream.

## Parameters

None.
# SwisTrack/Components/OutputImageStatisticsBinary
## Description

This component calculates and outputs the following statistical values of a binary image:
* Number of non-zero pixels
* Sum of all pixels
* Mean and standard deviation of all pixels
* Minimum and maximum value among all pixels
Combined with (adaptive) background subtraction, such values are useful to detect sudden changes or out-of-the-ordinary frames in a video stream.

## Input

A binary image.

## Output

The statistical values are written to the NMEA stream.

## Parameters

Each of the values mentioned above can be enabled or disabled. For performance reasons, it is advisable to enable only those values which are needed.
# SwisTrack/Components/OutputFile
## Description

This component allows to write the tracking data to a file. The data are all the data contained in the particles. But only the particles linked to a track will be saved. The ID of the track is linked to the ID of the particle. One file named "track_##.txt" is generated for each track, with ## being the ID of the track. The file is compatible with matlab and can be directly loaded.

## Input

The tracks resulting of the tracking

## Output

One file for each track, containing the data of the tracked object, in a tab separated format.

## Parameters
### Output Directory

Name of the directory where the files have to be saved.
# SwisTrack/Components/OutputFileAVI
## Description

This component allows to write an avi file to record the image. Beware that the place where this component is used has a big influence on the result, as it use the images that are processed. For example, showing the black and white image after the blob selection will show only the selected blobs. As a rule of thumb, the display will corresponds to what is displayed in the last previous component displaying the wanted image.

## Input

The gray, the color or the binary image.

## Output

A grayscale or a color image

## Parameters
### File

Path to the video file to write.

### Codec code

Corresponds to the codec used to encode the video file. If set to "Def.", on Windows, it uses CV_FOURCC_PROMPT (open an interface to select the codec, but not working in the current 1.1pre1a version) and on linux, it uses the default coded for the type of file you are saving to (CV_FOURCC_DEFAULT).
You can also use code hidden in the cvcap_ffmpeg.cpp file of the OpenCV, HighGui library, used by the CV_FOURCC function.
Here are some possible codes:
| 4 characters code | Corresponding codec |
| PIM1 | MPEG-1 codec |
| MJPG | motion-jpeg codec (does not work well) |
| MP42 | MPEG-4.2 codec |
| DIV3 | MPEG-4.3 codec |
| DIVX | MPEG-4 codec |
| U263 | H263 codec |
| I263 | H263I codec |
| FLV1 | FLV1 codec |
A more extensive list of fourcc codecs can be found on FOURCC.org.

### Frame Rate

Frame rate of the resulting avi file. It can be different from the input frame rate.

### Input Image

Select the input image to be recorded. You can choose between the gray, the color or the black and white image.

### Buffer Frames

Number of frames kept in the buffer. If 1, no buffering is performed at all.
# SwisTrack/Components/OutputFramesImages
## Description

This component allows to record the image by saving each frame to a separate image file. These images can be used by other programs, or, for example they can be converted into a video with mplayer.
Beware that the place where this component is used has a big influence on the result, as it use the images that are processed. For example, showing the black and white image after the blob selection will show only the selected blobs. As a rule of thumb, the display will corresponds to what is displayed in the last previous component displaying the wanted image.

## Input

The gray, the color or the binary image.

## Output

The images as separate files.

## Parameters
### Prefix

The filename prefix to use. Frame number and file extension will be added automatically.
The frame number will be zero-padded to 8 chars, so that alphabetical order of the filenames will correspond to the numerical order of the frames.
If the prefix contains directories (for example, it is 'frames/frame') those directories will be created as needed.

### File type

Note that png format is quite slow. bmp is very fast, but the resulting files are pretty big.
# SwisTrack/Components/NearestNeighborTracking
## Description

Basic tracking component; takes pre-filtered particles (use the BlobSelection and BlobDetection components before this one) and adds each of them to the track nearest to it. IMPORTANT: Make sure that the number of tracks and the max number of particles in BlobDetection are the same, and that exactly that number of targets are present

## Parameters
### Max distance

The maximum distance between a track and a particle to attach.

### Max number

The maximum number of objects to track. Should be the same as the maximum number of particles in blob detection.
# SwisTrack/Components/OutputMarkFrameManual
## Description

This component writes MARK messages to the NMEA stream, whenever the user clicks a button. This is useful if observations have to be made by the user watching the video.

## Input

None.

## Output

The MARK messages are written to the NMEA stream.

## Parameters

None.
# SwisTrack/Components/OutputSQLite
## Description

This component writes the tracking data to a SQLite database.

## Input

The tracks resulting from the tracking.

## Output

A SQLite3 database at the parameterized path. The database contains two tables:
* points : contains the tracks
* configuration : a series of key-value pairs including the configuration that was used to generate the tracks, the machine it was run on, start time, etc.

## Parameters

The three parameters to this component are:
* Directory in which to place the output database.
* Filename to be used for said database.
* Whether or not an existing database at the specified path should be appended to, or cleared before use.