{"action":"created","issue":{"url":"https://api.github.com/repos/obdurodon/dh_course/issues/177","repository_url":"https://api.github.com/repos/obdurodon/dh_course","labels_url":"https://api.github.com/repos/obdurodon/dh_course/issues/177/labels{/name}","comments_url":"https://api.github.com/repos/obdurodon/dh_course/issues/177/comments","events_url":"https://api.github.com/repos/obdurodon/dh_course/issues/177/events","html_url":"https://github.com/obdurodon/dh_course/issues/177","id":395118857,"node_id":"MDU6SXNzdWUzOTUxMTg4NTc=","number":177,"title":"Using tokenize() with Schematron","user":{"login":"zme1","id":25443822,"node_id":"MDQ6VXNlcjI1NDQzODIy","avatar_url":"https://avatars0.githubusercontent.com/u/25443822?v=4","gravatar_id":"","url":"https://api.github.com/users/zme1","html_url":"https://github.com/zme1","followers_url":"https://api.github.com/users/zme1/followers","following_url":"https://api.github.com/users/zme1/following{/other_user}","gists_url":"https://api.github.com/users/zme1/gists{/gist_id}","starred_url":"https://api.github.com/users/zme1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zme1/subscriptions","organizations_url":"https://api.github.com/users/zme1/orgs","repos_url":"https://api.github.com/users/zme1/repos","events_url":"https://api.github.com/users/zme1/events{/privacy}","received_events_url":"https://api.github.com/users/zme1/received_events","type":"User","site_admin":false},"labels":[{"id":864639002,"node_id":"MDU6TGFiZWw4NjQ2MzkwMDI=","url":"https://api.github.com/repos/obdurodon/dh_course/labels/Topic:%20Schematron","name":"Topic: Schematron","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-01-01T22:59:01Z","updated_at":"2019-01-01T22:59:36Z","closed_at":null,"author_association":"NONE","body":"I started working on the second schematron assignment, and quickly ran into the problem of how to count hyphens and spaces. I'm not quite sure how to write an Xpath expression to find that exactly, so I searched the internet for answers. I only found examples using XSLT, where one can declare variables. Currently, I am thinking that I need the count, tokenize and string functions. Any help would be sincerely appreciated.\r\n\r\nHere is what I have so far:\r\n```\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<sch:schema xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" queryBinding=\"xslt2\"\r\n    xmlns:sqf=\"http://www.schematron-quickfix.com/validator/process\"\r\n    xmlns=\"http://purl.oclc.org/dsdl/schematron\">\r\n    <pattern>\r\n        <rule context=\"sentence\">\r\n            <assert test=\"count(tokenize(string('-')))\">The number of hypens must match in orth, translit and ilg.</assert>\r\n        </rule>\r\n    </pattern>\r\n</sch:schema>\r\n```"},"comment":{"url":"https://api.github.com/repos/obdurodon/dh_course/issues/comments/450763416","html_url":"https://github.com/obdurodon/dh_course/issues/177#issuecomment-450763416","issue_url":"https://api.github.com/repos/obdurodon/dh_course/issues/177","id":450763416,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDc2MzQxNg==","user":{"login":"zme1","id":25443822,"node_id":"MDQ6VXNlcjI1NDQzODIy","avatar_url":"https://avatars0.githubusercontent.com/u/25443822?v=4","gravatar_id":"","url":"https://api.github.com/users/zme1","html_url":"https://github.com/zme1","followers_url":"https://api.github.com/users/zme1/followers","following_url":"https://api.github.com/users/zme1/following{/other_user}","gists_url":"https://api.github.com/users/zme1/gists{/gist_id}","starred_url":"https://api.github.com/users/zme1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zme1/subscriptions","organizations_url":"https://api.github.com/users/zme1/orgs","repos_url":"https://api.github.com/users/zme1/repos","events_url":"https://api.github.com/users/zme1/events{/privacy}","received_events_url":"https://api.github.com/users/zme1/received_events","type":"User","site_admin":false},"created_at":"2019-01-01T22:59:36Z","updated_at":"2019-01-01T22:59:36Z","author_association":"NONE","body":"count(), tokenize(), and string functions are all part of XPath, which means that they're all available inside Schematron, just as they are in XSLT or XQuery. We used the count() and sum() functions in class today; you can use any other XPath function the same way.\r\n\r\nIn your sample, you've wrapped string() around a one-character string that consists of a single hyphen, so the output of the string() function will be the same as the input: it will convert the string you already have into a string that's identical to it—that is, it doesn't do what you want. Your syntax for tokenize() is problematic because tokenize() requires two arguments: the string that you're breaking into pieces and the regex that you're using to identify where to break. You'll want to look this up in Michael Kay (concentrate on the examples) or w3schools, which is what we do when we use functions we haven't used before, too. We also use tokenize() in the Skyrim example, to which we've linked in the Schematron section of our main course page, so you can see it in action there, as well.\r\n\r\nAt the moment, your tokenize() function has only one argument, so you'll raise an error. But you're on the right track: if you divide \"blah-blah-blah\" into pieces by tokenizing on a hyphen and then count the pieces, you'll get a count of three. There are actually two hyphens, but you can get equally useful results from counting pieces as you get from counting hyphens, since you need a comparison, and not an exact count. That is, if each tier has three tokens, that's as good as verifying that each tier has two hyphens.\r\n\r\nAnd comparison is the next step: your test can't just fix the tokenize() syntax to count the number of hyphens in one of the tiers; it has to compare that to a count of the hyphens in another tier, and test whether the counts are equal. There are several ways to approach this problem (since there are multiple tiers), but one way to think about it is that if you want to verify that the number of hyphens in the tiers is consistent, you need to compare those counts to one another.\r\n\r\nYou did some comparisons of stooge data in class today, so you have some ideas about how to think about translating the human expression of this type of problem into Schematron and XPath. But this is a harder problem than the one with the stooges, so we'd suggest turning it into a bunch of smaller, easier problems and approaching it step by step. The first step is making sure you can get tokenize() to return the type of information you need, and you can do that by experimenting with it in the XPath browser box in the upper left corner or writing a short XSLT stylesheet to output some diagnostic information. Once you can tokenize one of the tiers, you'll want to work on comparing the counts of just two tiers, whether for hyphens or for spaces. Once you have that working, you can expand the task to include all of the comparisons. For what it's worth, that's how we developed our own Schematron in our own projects: we get the XPath working first and then we incorporate it into the Schematron shell.\r\n\r\nNote that we've simplified the problem by doing the comparisons among the entire text of the tiers. You don't have to compare word by word; that's possible, but very difficult, and if you can do the comparison just on the entire text of the tiers, that's a good outcome."}}
{"actor":{"display_login":"zme1"}}