XSLTC Internal DOM
- General functionlaity
- Components of the internal DOM
- Internal structure
- Tree navigation
- Namespaces
- W3C DOM2 navigation support
- The DOM adapter - DOMAdapter
- The DOM multiplexer - MultiDOM
- The DOM builder - DOMImpl$DOMBuilder
General functionality
The internal DOM gives the translet access to the XML document(s) it has to transform. The interface to the internal DOM is specified in the DOM.java class. This is the interface that the translet uses to access the DOM. There is also an interface specified for DOM caches -- DOMCache.java
Components of the internal DOM
This DOM interface is implemented by three classes:
-
org.apache.xalan.xsltc.dom.DOMImpl
This is the main DOM class. An instance of this class contains the nodes of a single XML document.
-
org.apache.xalan.xsltc.dom.MultiDOM
This class is best described as a DOM multiplexer. XSLTC was initially designed to operate on a single XML document, and the initial DOM and the DOM interface were designed and implemented without thedocument()
function in mind. This class will allow a translet to access multiple DOMs through the original DOM interface.
-
org.apache.xalan.xsltc.dom.DOMAdapter
The DOM adapter is a mediator between a DOMImpl or a MultiDOM object and a single translet. A DOMAdapter object contains mappings and reverse mappings between node types in the DOM(s) and node types in the translet. This mediator is needed to allow several translets access to a single DOM.
-
org.apache.xalan.xsltc.dom.DocumentCache
A sample DOM cache (implementing DOMCache) that is used with our sample transformation applications.
Figure 1: Main components of the internal DOM
The figure above shows how several translets can access one or more
internal DOM from a shared pool of cached DOMs. A translet can also access a
DOM tree outside of a cache. The Stylesheet class that represents the XSL
stylesheet to compile contains a flag that indicates if the translet uses the
document()
function. The code compiled into the translet will act
accordingly and instanciate a MultiDOM object if needed (this code is compiled
in the compiler's Stylesheet.compileTransform()
method).
Internal Structure
- Node identification
- Element nodes
- Attribute nodes
- Text nodes
- Comment nodes
- Processing instructions
Node identifation
Each node in the DOM is represented by an integer. This integer is an
index into a series of arrays that describes the node. Most important is
the _type[]
array, which holds the (DOM internal) node type. There
are some general node types that are described in the DOM.java interface:
public final static int ROOT = 0; public final static int TEXT = 1; public final static int UNUSED = 2; public final static int ELEMENT = 3; public final static int ATTRIBUTE = 4; public final static int PROCESSING_INSTRUCTION = 5; public final static int COMMENT = 6; public final static int NTYPES = 7;
Element and attribute nodes will be assigned types based on their expanded
QNames. The _type[]
array is used for this:
int type = _type[node]; // get node type
The node type can be used to look up the element/attribute name in the
element/attribute name array _namesArray[]
:
String name = _namesArray[type-NTYPES]; // get node element name
The resulting string contains the full, expanded QName of the element or attribute. Retrieving the namespace URI of an element/attribute is done in a very similar fashion:
int nstype = _namespace[type-NTYPES]; // get namespace type String namespace = _nsNamesArray[nstype]; // get node namespace name
Element nodes
The contents of an element node (child nodes) can be identified using
the _offsetOrChild[]
and _nextSibling[]
arrays.
This value is OK since the root node (the 0 node) will not be a child of
any element.
Attribute nodes
The first attribute node of an element is found by a lookup in the
_lengthOrAttr[]
array using the node index:
int attribute = _offsetOrChild[node]; // first attribute attribute = _nextSibling[attribute]; // next attribute
The names of attributes are contained in the _namesArray[]
just
like the names of element nodes. The value of attributes are store the same
way as text nodes:
int offset = _offsetOrChild[attribute]; // offset into character array int length = _lengthOrAttr[attribute]; // length of attribute value String value = new String(_text, offset, length);
Text nodes
Text nodes are stored identically to attribute values. See the previous section on attribute nodes.
Comment nodes
The internal DOM does currently not contain comment nodes. Yes, I am quite aware that the DOM has a type assigned to comment nodes, but comments are still not inserted into the DOM.
Processing instructions
Processing instructions are handled as text nodes. These nodes are stored identically to attribute values. See the previous section on attribute nodes.
Tree navigation
The DOM implementation contains a series of iterator that implement the
XPath axis. All these iterators implement the NodeIterator interface and
extend the NodeIteratorBase base class. These iterators do the job of
navigating the tree using the _offsetOrChild[]
, _nextSibling
and _parent[]
arrays. All iterators that handles XPath axis are
implemented as a private inner class of DOMImpl. The translet uses a handful
of methods to instanciate these iterators:
public NodeIterator getIterator(); public NodeIterator getChildren(final int node); public NodeIterator getTypedChildren(final int type); public NodeIterator getAxisIterator(final int axis); public NodeIterator getTypedAxisIterator(final int axis, final int type); public NodeIterator getNthDescendant(int node, int n); public NodeIterator getNamespaceAxisIterator(final int axis, final int ns); public NodeIterator orderNodes(NodeIterator source, int node);
There are a few iterators in addition to these, such as sorting/ordering iterators and filtering iterators. These iterators are implemented in separate classes and can be instanciated directly by the translet.
Namespaces
Namespace support was added to the internal DOM at a late stage, and the design and implementation of the DOM bears a few scars because of this. There is a separate design document that covers namespaces.
W3C DOM2 navigation support
The DOM has a few methods that give basic W3C-type DOM navigation. These methods are:
public Node makeNode(int index); public Node makeNode(NodeIterator iter); public NodeList makeNodeList(int index); public NodeList makeNodeList(NodeIterator iter);
These methods return instances of inner classes of the DOM that implement the W3C Node and NodeList interfaces.
The DOM adapter - DOMAdapter
Translet/DOM type mapping
The DOMAdapter class performs the mappings between DOM and translet node types, and vice versa. These mappings are necessary in order for the translet to correctly identify an element/attribute in the DOM and for the DOM to correctly identify the element/attribute type of a typed iterator requested by the translet. Note that the DOMAdapter also maps translet namespace types to DOM namespace types, and vice versa.
The DOMAdapter class has four global tables that hold the translet/DOM
type and namespace-type mappings. If the DOM knows an element as type
19, the DOMAdapter will translate this to some other integer using the
_mapping[]
array:
int domType = _mapping[transletType];
This action will be performed when the DOM asks what type a specific node
is. The reverse is done then the translet wants an iterator for a specific
node type. The DOMAdapter must translate the translet-type to the type used
internally in the DOM by looking up the _reverse[]
array:
int transletType = _mapping[domType];
There are two additional mapping tables: _NSmapping[]
and
_NSreverse[]
that do the same for namespace types.
Whitespace text-node stripping
The DOMAdapter class has the additional function of stripping whitespace nodes in the DOM. This functionality had to be put in the DOMAdapter, as different translets will have different preferences for node stripping.
Method mapping
The DOMAdapter class implements the same DOM
interface as the
DOMImpl class. A DOMAdapter object will look like a DOMImpl tree, but the
translet can access it directly without being concerned with type mapping
and whitespace stripping. The getTypedChildren()
demonstrates very
well how this is done:
public NodeIterator getTypedChildren(int type) { // Get the DOM type for the requested typed iterator final int domType = _reverse[type]; // Now get the typed child iterator from the DOMImpl object NodeIterator iterator = _domImpl.getTypedChildren(domType); // Wrap the iterator in a WS stripping iterator if child-nodes are text nodes if ((domType == DOM.TEXT) && (_filter != null)) iterator = _domImpl.strippingIterator(iterator,_mapping,_filter); return(iterator); }
The DOM multiplexer - MultiDOM
The DOM multiplexer class is only used when the compiled stylesheet uses
the document()
function. An instance of the MultiDOM class also
implements the DOM interface, so that it can be accessed in the same way
as a DOMAdapter object.
A node in the DOM is identified by an integer. The first 8 bits of this integer are used to identify the DOM in which the node belongs, while the lower 24 bits are used to identify the node within the DOM:
| 31-24 | 23-16 | 16-8 | 7-0 |
| DOM id | node id |
The DOM multiplexer has an array of DOMAdapter objects. The topmost 8 bits of the identifier is used to find the correct DOM from the array. Then the lower 24 bits are used in calls to methods in the DOMAdapter object:
public int getParent(int node) { return _adapters[node>>>24].getParent(node & 0x00ffffff) | node & 0xff000000; }
Note that the node identifier returned by this method has the same upper 8
bits as the input node. This is why we OR
the result from
DOMAdapter.getParent()
with the top 8 bits of the input node.
The DOM builder - DOMImpl$DOMBuilder
- startElement()
- endElement()
- startPrefixMapping()
- endPrefixMapping()
- characters()
- startDocument()
- endDocument()
The DOM builder is an inner class of the DOM implementation. The builder
implements the SAX2 ContentHandler
interface and populates the DOM
by receiving SAX2 events from a SAX2 parser (presently xerces). An instance
of the DOM builder class can be retrieved from DOMImpl.getBuilder()
method, and this handler can be set as an XMLReader's content handler:
final SAXParserFactory factory = SAXParserFactory.newInstance(); final SAXParser parser = factory.newSAXParser(); final XMLReader reader = parser.getXMLReader(); final DOMImpl dom = new DOMImpl(); reader.setContentHandler(dom.getBuilder());
The DOM builder will start to populate the DOM once the XML parser starts generating SAX2 events:
startElement()
This method can be called in one of two ways; either with the expanded
QName (the element's separate uri and local name are supplied) or as a
normal QName (one String on the format prefix:local-name). The DOM stores
elements as expanded QNames so it needs to know the element's namespace URI.
Since the URI is not supplied with this call, we have to keep track of
namespace prefix/uri mappings while we're building the DOM. See
startPrefixMapping()
below for details on
namespace handling.
The startElement()
inserts the element as a child of the current
parent element, creates attribute nodes for all attributes in the supplied
"Attributes
" attribute list (by a series of calls to
makeAttributeNode()
), and finally creates the actual element node
(by calling internElement()
, which inserts a new entry in the
_type[]
array).
endElement()
This method does some cleanup after the startElement()
method,
such as revering xml:space
settings and linking the element's
child nodes.
startPrefixMapping()
This method is called for each namespace declaration in the source
document. The parser should call this method before the prefix is referenced
in a QName that is passed to the startElement()
call. Namespace
prefix/uri mappings are stored in a Hashtable structure. Namespace prefixes
are used as the keys in the Hashtable, and each key maps to a Stack that
contains the various URIs that the prefix maps to. The URI on top of the
stack is the URI that the prefix currently maps to.
Figure 2: Namespace handling in the DOM builder
Each call to startPrefixMapping()
results in a lookup in the
Hashtable (using the prefix), and a push()
of the URI onto the
Stack that the prefix maps to.
endPrefixMapping()
A namespace prefix/uri mapping is closed by locating the Stack for the
prefix, and then pop()
'ing the topmost URI off this Stack.
characters()
Text nodes are stored as simple character sequences in the character array
_text[]
. The start and lenght of a node's text can be determined by
using the node index to look up _offsetOrChild[]
and
_lengthOrAttribute[]
.
We want to re-use character sequences if two or more text nodes have
identical content. This can be achieved by having two different text node
indexes map to the same character sequence. The maybeReuseText()
method is always called before a new character string is stored in the
_text[]
array. This method will locate the offset of an existing
instance of a character sequence.
startDocument()
This method initialises a bunch of data structures that are used by the
builder. It also pushes the default namespace on the namespace stack (so that
the "" prefix maps to the null
namespace).
endDocument()
This method builds the _namesArray[]
, _namespace[]
and _nsNamesArray[]
structures from temporary datastructures used
in the DOM builder.


MultiDatesPicker(model as array of Date) inline: input: {{dates}} MultiDatesPicker(Limited by list) inline: {{restrictedDates}}


This is a short paragraph to introduce the article (but it is not the abstract). It is optional, in case it would be preferable to have the first section be titled an “Introduction.”


Welcome to SkoTutoring !

Student
Click here if you are a student.


Structured data with schema.org codelab
By
Author Name
,
January 29, 2014
About this codelab
Exercise 1: From basic HTML to RDFa: first steps
Exercise 2: Embedded types
Exercise 3: From strings to things


One drop every X seconds.
X drops every second.
X drops every 5 seconds.
X mL (X L) per 4 hours.
X mL (X L) per day.


Hello from h6
I just want
To inform you that
Right now, I'm learning
About heading elements in HTML
And I must say that it's not so complex
On the countrary, it's interesting
And can't wait to
Move forward
Learn new things
About HTML


Individual Learning
Objectives
- Revise the design of your together app.
- Create an initial sketch of the required data model.
Revise
Revise your design to meet the two requirements below:
- The client screen should fit in an iPad screen (768 x 1024). A user should not need to scroll.
- The client should be able to have awareness of what every other user is
doing concurrently. For instance, in Google Doc, you can see which sentence
or word another user is currently editing. In Slack, you can see whether
each person is currently typing. What would be your app’s awareness feature?
Data Models
Write a sketch of the data models you will need in the real-time database (Firebase)
in order to support your app.
Submission


Source code for Downloader.ImageHelpers
import numpy as np
from scipy.misc import imread, imresize, imsave
from keras.preprocessing.image import *
from Downloader.Defaults import KERAS_SETTING_DIMENSIONS
# Helper functions for loading of images
[docs]def list_images(folder):
''' prepare list of image names '''
from os import listdir
from os.path import isfile, join
image_list = [folder + f for f in listdir(folder) if isfile(join(folder, f))]
return image_list
[docs]def len_(L):
return np.array(L).shape
[docs]def load_image_with_keras(img_path, target_size=None, dim_ordering=KERAS_SETTING_DIMENSIONS):
pil_img = load_img(img_path, target_size)
arr = img_to_array(pil_img, dim_ordering)
return arr
[docs]def load_images_with_keras(img_paths, target_size=None, dim_ordering=KERAS_SETTING_DIMENSIONS):
imgs_arr = []
for img_path in img_paths:
arr = load_image_with_keras(img_path, target_size, dim_ordering)
imgs_arr.append(arr)
return imgs_arr
[docs]def preprocess_image_batch(image_paths, img_size=None, crop_size=None, color_mode="rgb", out=None):
img_list = []
for im_path in image_paths:
img = imread(im_path, mode='RGB')
if img_size:
try:
img = imresize(img,img_size)
except:
print 'failed resizing image', im_path
raise
img = img.astype('float32')
## We normalize the colors (in RGB space) with the empirical means on the training set
#img[:, :, 0] -= 123.68
#img[:, :, 1] -= 116.779
#img[:, :, 2] -= 103.939
# We permute the colors to get them in the BGR order
if color_mode=="bgr":
img[:,:,[0,1,2]] = img[:,:,[2,1,0]]
img = img.transpose((2, 0, 1))
if crop_size:
img = img[:,(img_size[0]-crop_size[0])//2:(img_size[0]+crop_size[0])//2
,(img_size[1]-crop_size[1])//2:(img_size[1]+crop_size[1])//2]
img_list.append(img)
try:
img_batch = np.stack(img_list, axis=0)
except:
raise ValueError('when img_size and crop_size are None, images'
' in image_paths must have the same shapes.')
if out is not None and hasattr(out, 'append'):
out.append(img_batch)
else:
return img_batch
[docs]def saveArrayToCSV(array,filename):
a = np.asarray(array)
np.savetxt(filename, a, delimiter=",")


{# basic/localtoc.html ~~~~~~~~~~~~~~~~~~~ Sphinx sidebar template: local table of contents. :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. Should probably change the url destination to something "on this page" #} {%- if display_toc %}


Overview
Personal Trainer Pro is a free to use application used for helping personal trainers gauge the improvement of their clients as well as help them improve. It comes with a highly capable Command Line Interface(CLI) personal organiser and tracker keep together with an easy to use interface. The Graphical User Interface(GUI) is very simplistic but extremely detailed and easy to use to aid trainers in helping their clients. The user interacts with it using a CLI, and it has a GUI created with JavaFX. It is written in Java, and has about 10 kLoC.
Summary of contributions
-
Major enhancement: added Calories Calculator
-
What it does: allows the user/trainer to calculate the required calories based on a reliable website to obtain the best amount of calories the clients should have in order to improve, grow or lose weight. It uses all attribute data of the client to find the amount of calories needed.
-
Justification: This feature will allow for trainers to quickly and readily answer questions about the client and also choose a perfect workout to suit the needs and wants, be it to gain lose or maintain, of the client.
-
Highlights: This feature required additional attributes being added on to the original base and handling of events and creation of specific tests for each attribute before combining everything.
-
Credits: Calculator.net was used as the main calculator that was being build around.
-
**External behaviour ---
-
Minor enhancement: added a html design when selecting the personal card in order to improve aesthetics and remove clutter.
**External behaviour ---
-
Code contributed: [https://github.com/CS2103JAN2018-F12-B2/main/blob/master/collated/functional/hypertun.md] [https://github.com/CS2103JAN2018-F12-B2/main/blob/master/collated/test/hypertun.md]
-
Future implementation: *Tracking Weight for clients What it does: This will allow for trainers as well as clients to track their progress to reach their goal. Justification: As the clients progress using the calories calculator it is important that they track their progress whether to gain weight, lose weight or to maintain weight. It already has a preliminary design as shown below in other contributions.
-
Other contributions: Tried to implement the weight log attribute but was unsuccessful. (Pull request(s): #40)
-
Project management:
-
Managed releases
v1.0
-v1.5rc
(6 releases) on GitHub
-
-
Enhancements to existing features:
-
Documentation:
-
Community:
-
Contributions to the User Guide
Given below are sections I contributed to the User Guide. They showcase my ability to write documentation targeting end-users. |
Show Calories a person requires : Calories
Selects the person identified by the index number and shows the amount of calories needed to increase or decrease in weight.
Format: Calories INDEX
Alias: cal
Examples:
-
list
Calories 2
Shows the calories of the 2nd person in the address book. -
find Betsy
cal 1
Shows the calories of the 1st person in the results of thefind
command.
Contributions to the Developer Guide
Given below are sections I contributed to the Developer Guide. They showcase my ability to write technical documentation and the technical depth of my contributions to the project. |
@by Ivan
Gender attribute : Current Implementation
The Gender attribute only accepts male and female genders. This is shown by only accepting characters M, F, m and f and only single letters are accepted. The 'GENDER_VALIDATION_REGEX' ensures that only the selected single alphabets are able to be input into the command line.
The Gender attribute resides as an attribute to a person under 'model'. This means that every Person added by the AddCommand line must have a gender.
Gender is implemented in this way:
---
public class Gender {
public static final String MESSAGE_GENDER_CONSTRAINTS = "Gender can only be the alphabets M or F or m or f"; public static final String GENDER_VALIDATION_REGEX = "[mfMF]{1}+"; public final String value; //... rest of attribute functions ...
// Test for regex is shown below public static boolean isValidGender(String test) { return test.matches(GENDER_VALIDATION_REGEX); }
//... rest of attribute functions ... } ---
Supposed the user has just created a person using the command line but the gender is null or not within the regex this will cause a failure in execution of the AddCommand and a display of the 'MESSAGE_GENDER_CONSTRAINTS'.
The same applies to the Editfunction where the same checks will apply. However this attribute differs from the name attribute as it can be duplicated to different persons.
AddCommand:
---
@Override
public CommandResult executeUndoableCommand() throws CommandException {
requireNonNull(model);
try {
model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (DuplicatePersonException e) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
} ---
EditCommand:
---
@Override
public CommandResult executeUndoableCommand() throws CommandException {
try {
model.updatePerson(personToEdit, editedPerson);
} catch (DuplicatePersonException dpe) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
} catch (PersonNotFoundException pnfe) {
throw new AssertionError("The target person cannot be missing");
}
//... rest of edit command ...
}
---
As one can see it will throw an exception be it either command when a duplicate person is found.
Design Considerations
Aspect: Implementation of Gender
attribute
-
Alternative 1 (current choice): Add a new gender attribute to person 'g/'.
-
Pros: We will not lose any undone/redone functionality as it is now part of the default behaviour.
-
Cons: It will now require constant addition of the gender attribute to a person even when the gender attribute is not needed in some cases.
-
-
Alternative 2: Add gender as a tag
-
Pros: It will not require a constant addition of the gender attribute, only added for the times it is needed.
-
Cons: UI looks messy as some will have gender tags and some will not have gender tags which does not make sense, since everyone has a gender.
-
Appendix A: Glossary
- Mainstream OS
-
Windows, Linux, Unix, OS-X
- Private contact detail
-
A contact detail that is not meant to be shared with others
- Personal trainer
-
Target audience
- Trainer
-
Same as above
- Client
-
Indirect target audience, due the the fact the employer-employee relationship between them and trainers
- Track
-
Understanding the fitness(e.g. weight loss/gain, calories, protein) progress of the clients
- Meal plan
-
A combination of dietary information that should be followed
- Training
-
A period of time when client is working out
- Session
-
Same as above
- Appointment
-
Same as above
- Goals
-
A combination of desirable attributes that clients want to achieve
Other Contributions
Collated the code together. (#108)


--- layout: archive title: Zulip Chat Archive permalink: /stream/113488-general/topic/lean.20killed.20my.20machine.html ---
The perfectoid project is now 11,000 lines long. A couple of times recently I have idly typed "lean --make" to compile it, and brought my (16 gigs of ram) machine down -- it becomes unresponsive, the keyboard lights don't work and I can't ssh into it, and I've had to reboot. More recently (I'm on Ubuntu) I've been typing ulimit -Sv 8000000
in the terminal window I use to compile the project, and this stopped the problem occurring until today, where I wasn't even compiling: VS Code just decided to recompile a few files and my system was taken down again.
I am on Ubuntu 18.04 with no swap (because I have an SSD). I am wondering whether enabling swap will give me extra time to survive the next time this happens; I have an external HDD drive now.
I mean every time I run Lean my laptop turns scorching hot
Yes but that just means it's using all the cores. Lean shouldn't take your system down; that means it's filled all the memory.
Now when this happens Lean will start using my swap space, so I'll hear the external HD fire up and start going like crazy, and that will be the signal to kill everything.
could try https://github.com/rfjakob/earlyoom
Well, I now have a 4GB swapfile on my external hard drive. Let's see how things go now. I like the look of earlyoom though.
{% endraw %}Last updated: Apr 24 2020 at 19:02 UTC


nerdy.js
A data analysis and machine learning toolkit for Javascript.
Utility functions
- parse a string of delimited data
- evaluate a polynomial at some point
- sum values in array
- sum of squares values in array
- mean of array
- variance of array
- standard deviation of array
- minimum value of array
- maximum value of array
- median of array
- skewness of array
- kurtosis of array
Primary dataset model is nerdy.Dataset, supporting:
- loading data from arrays or delimited text
- querying the data
- extracting arrays of numbers
- update dataset
Available math tools:
Available stats tools:
- descriptive statistics
- one-way ANOVA, variance, covariance, and correlation methods
- normalcdf, normalarea, and random.normal for dealing with normal distributions
- linear regression (can be expanded to polynomial)
- logistic regression (can be expanded to polynomial)


On a dark stormy day, a very severe pandemic blew up in Alt-NUS.
Unfortunately, there's no cure for it yet.
However, one CAP 5 scholar from computing went to the SoC supercomputer cluster,
used his big brains to design a neural network,
and found a recipe for the cure!
Apparently the cure was hidden in plain sight, only consisting of common ingredients.
He also discovered that a Pokemon is behind this pandemic. Who's that Pokemon?
COVID Be Gone
- 2 tablespoons of apple cider vinegar
- 2 tablespoons of honey
- 2 tablespoons of water
- 1/4 teaspoon of cayenne pepper
- 1/4 teaspoon of ground ginger


Now spring has come to Oxfordshire And sunshine to the city There's people in the parks, because The parks are looking pretty.
The uni' owns the land along The lazy River C, That gives oxygenated bliss To God, and man, and me.
The flowers by the entrance were All yellow and vermillion - I passed them on the way towards The cricketing pavilion.

So, as I lay upon the grass And stretched, and yawned, at ease, A flagpole that's without a flag Was tickled by a breeze.