Why does sh:NodeShape not have sh:name and sh:description properties? - shacl

When reading the SHACL specification I noticed we can add a sh:name and sh:description to a sh:PropertyShape which is meant to
provide human-readable labels for the property in the target where it appears
which is really cool for properties but I am a bit confused why this is not the case for sh:NodeShape too. Would it not be helpful to provide human-readable names and descriptions for 'types' too?

For node shapes, simply use rdfs:label and rdfs:comment. These properties already exist and are used for similar annotation purposes, e.g. for classes.
We needed to mint new properties for property shapes because rdfs:label and rdfs:comment would be about the sh:PropertyShape itself while sh:name and sh:description are about the sh:path of the property shape.

Related

RuboCop style suggestion: "Pass '$:to_i' as an argument to 'Transform' instead of a block."

I guess I'm not quite understanding the style suggestion. I'm passing a regexp to Transform, is this considered a "block"? And how do I pass $:key to Transform in this situation?
CAPTURE_CASH_AMOUNT = Transform(/^\$(\d+)$/) do |digits|
digits.to_i
end
[...] is this considered a "block"?
Anything wrapped in do-end is a block in Ruby.
And how do I pass &:key to Transform in this situation?
Ruby implements Symbol#to_proc for you, to allow the shorthand &:method argument for block that send a single method to the yielded object.
In your case, this is equivalent:
CAPTURE_CASH_AMOUNT = Transform(/^\$(\d+)$/, &:to_i)

Can I have multiple values in one HTML "data-" element?

Can I have multiple values in one HTML "data-" element? Similar to how a class can have multiple class names.
If possible, I would like to create a CSS/JS library that makes use of one "data-" element to house all of the library styles. For example:
<div data-library-name="xs-hidden col-md-10 col-xl-8 big-hero"></div>
That way, any of the programmers custom style rules can go into the elements class. My reasoning for this is to make readability easier, so together it would look like:
<div class="custom-style another-style" data-library-name="xs-hidden col-md-10 col-xl-8 big-hero"></div>
Can I have multiple values in one HTML "data-" element?
You can have a string. The spec doesn't define any particular format for the data in the attribute, which is designed to be processed by site specific JavaScript.
Similar to how a class can have multiple class names.
The class attribute takes a space separated list of classes.
Your JavaScript can your_data_attribute_value.split(" "); if you like.
Handling this with CSS would use the ~= attribute selector.
[att~=val]
Represents an element with the att attribute whose value is a whitespace-separated list of words, one of which is exactly "val". If "val" contains whitespace, it will never represent anything (since the words are separated by spaces). Also if "val" is the empty string, it will never represent anything.
AFAIK, I don't think data- attributes can convert that to an array. Instead, I think it'll interpret it as one value, but it is allowed.
If you want to do that, you'll probably have to split() it later in JavaScript into an array of usable values.
See this example on JSFiddle.net.
CSS has the shortcut .class selector but it actually is parsing the attribute named "class" as a list for space separated values. This is supported in the non-shortcut form by the following attribute selector:
[att~=val]
Represents an element with the att attribute whose value is a white space-separated list of words, one of which is exactly "val". If "val" contains white space, it will never represent anything (since the words are separated by spaces). If "val" is the empty string, it will never represent anything either.
Ref: http://www.w3.org/TR/CSS2/selector.html#class-html
As your question is tagged CSS you're perhaps looking for that. The rules how the parsing of attribute values is done is given in that document as well, so in case the javascript library you're trying to use on this (if any) won't cover that, it should be easy to add:
var list = $("div").data("library-name").split(/\s+/);
^^^^^^^^^^^^
This split with the white-space regular expression parses the string attribute value into an array with javascript and the Jquery library (for accessing the DOM and the data attribute).

Presenting fields in class diagram

class A
{};
class B
{
A a;
};
When I want to present the above classes in class diagram I can do it like this:
Where I can present that class B has a field of class A either by marking it with a line ended with a rhombus (1 in the picture) or by specifying class's field (2 in the picture). However, using both seems redundant. When should I use the former, when the latter? Is there any case when I should use both?
Edit: Actually 1 could either be aggregation or composition. Although, the concrete line type isn't important to my question, IMO.
Edit2: I've found a more or less real-life example of diagram where this situation occurs: http://en.wikipedia.org/wiki/Decorator_pattern#mediaviewer/File:Decorator_UML_class_diagram.svg Class Decorator contains a field of type Component.
There is no rule in UML,
but there are best practices.
UML Best Practice: Attribute or Association says about that
Use Associations for Classes and Attributes for DataTypes

How do I extract an HTML element based on its class?

I'm just starting out in Perl, and wrote a simple script to do some web scraping. I'm using WWW::Mechanize and HTML::TreeBuilder to do most of the work, but I've run into some trouble. I have the following HTML:
<table class="winsTable">
<thead>...</thead>
<tbody>
<tr>
<td class = "wins">15</td>
</tr>
</tbody>
</table>
I know there are some modules that get data from tables, but this is a special case; not all the data I want is in a table. So, I tried:
my $tree = HTML::TreeBuilder->new_from_url( $url );
my #data = $tree->find('td class = "wins"');
But #data returned empty. I know this method would work without the class name, because I've successfully parsed data with $tree->find('strong'). So, is there a module that can handle this type of HTML syntax? I scanned through the HTML::TreeBuilder documentation and didn't find anything that appeared to, but I could be wrong.
You could use the look_down method to find the specific tag and attributes you're looking for. This is in the HTML::Element module (which is imported by HTML::TreeBuilder).
my $data = $tree->look_down(
_tag => 'td',
class => 'wins'
);
print $data->content_list, "\n" if $data; #prints '15' using the given HTML
$data = $tree->look_down(
_tag => 'td',
class => 'losses'
);
print $data->content_list, "\n" if $data; #prints nothing using the given HTML
I'm using excellent (but a bit slow sometimes) HTML::TreeBuilder::XPath module:
my $tree = HTML::TreeBuilder::XPath->new_from_content( $mech->content() );
my #data = $tree->findvalues('//table[ #class = "winsTable" ]//td[#class = "wins"]');
(This is kind of a supplementary answer to dspain's)
Actually you missed a spot in the HTML::TreeBuilder documentation where it says,
Objects of this class inherit the methods of both HTML::Parser and HTML::Element. The methods inherited from HTML::Parser are used for building the HTML tree, and the methods inherited from HTML::Element are what you use to scrutinize the tree. Besides this (HTML::TreeBuilder) documentation, you must also carefully read the HTML::Element documentation, and also skim the HTML::Parser documentation -- probably only its parse and parse_file methods are of interest.
(Note that the bold formatting is mine, it's not in the documentation)
This indicates that you should read HTML::Element's documentation as well, where you would find the find method which says
This is just an alias to find_by_tag_name
This should tell you that it doesn't work for class names, but its description also mentions a look_down method which can be found slightly further down. If you look at the example, you'd see that it does what you want. And dspain's answer shows precisely how in your case.
To be fair, the documentation is not that easy to navigate.
I found the this link the most useful at telling me how to extract specific information from html content. I used the last example on the page:
use v5.10;
use WWW::Mechanize;
use WWW::Mechanize::TreeBuilder;
my $mech = WWW::Mechanize->new;
WWW::Mechanize::TreeBuilder->meta->apply($mech);
$mech->get( 'http://htmlparsing.com/' );
# Find all <h1> tags
my #list = $mech->find('h1');
# or this way <----- I found this way very useful to pinpoint exact classes with in some html
my #list = $mech->look_down('_tag' => 'h1',
'class' => 'main_title');
# Now just iterate and process
foreach (#list) {
say $_->as_text();
}
This seemed so much simpler to get up and running than any of the other modules that I looked at. Hope this helps!

tcl/tk button or toplevel pathname conventions

When one creates a new toplevel or button in TK, one needs to enter a pathname.
I have seen a basic code which looks like:
toplevel .a
...
button .a.b ...
My question is:
Are the dots treated differently than letters? Are they some sort of hierarchy delimiters, which create parent child relationship? I have looked at wiki TK and failed to find an answer to that.
Many thanks,
-Lior
As other answers have said, dots are used to represent a hierarchy, just as / or \ is used to represent a filesystem hierarchy.
Placing widgets in a hierarchy is not, strictly speaking, necessary. One advantage in doing so is that geometry managers such as grid and pack default to managing children in their parents. For example 'pack .a.b.c' will pack the widget a.b.c within the widget .a.b. This makes it easy to do simple layouts.
The same effect in many cases can be achieved by telling grid and pack into which container a child should be placed. Foe example, 'pack .c -in .a.b' will put the widget .c in the container .a.b. This let's you keep your hierarchy shallow, and makes refactoring a little easier.
See http://www.beedub.com/book/2nd/TKINTRO.doc.html for a good introduction to tk fundamentals.
Yes, they are! They separate for instance a frame with the content that are widgets:
set f [frame .hello]
button $f.b -text "Hello button"
pack $f.b
pack $f
As you can see in this example, the f is evaluated as variable, not f.b
You can also write pack ${f}.b but this is not needed as the dot is seen not to be part of the variable.
Yes - it's for the hierarchy. Have a look at TkDocs on the subject:
The frame, which was a child of the root, was named ".c". We could have put pretty much anything in place of the "c", naming it for example ".content". This name is purely for use by your program, so it's best to choose something meaningful. The controls that were children of the frame were given names like ".c.feet", ".c.meters", ".c.flbl", and so on. If there were any widgets at a deeper level of the hierarchy, we'd add another "." and then a unique identifier.