How to add variable number of values using swrl - protege4

This is my first post to stack overflow so I request for an encouraging reply :) (bonus reputations)
I am trying to use SWRL to do some calculations for me. To imitate the problem, I have created a small ontology using protege 4.3. It has only two classes Parent and Son. Instances include 1 parent (John) and three sons (son1, son2, son3). John is linked with 3 sons using "hasSon" object property. Age of each son is mentioned using "hasAge" data-type property (integers).
Question-1: I need to first check that how many instances are linked with a given Parent(John) using hasSon property. How this can be achieved in SWRL?
Question-2: After knowing the number of Sons then I have to add their ages to get the total age of all the Sons again using SWRL?
For me, this require a loop like addition (a=a+b) but I dont know how this will work in SWRL. I have attached the OWL code for you.
(Please note that in actual ontology the linked instances are not 3 but are varying and counting them is part of the problem)
Thanks in advance
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY parenttrial "http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#"
xml:base="http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:parenttrial="http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#hasSon -->
<owl:ObjectProperty rdf:about="&parenttrial;hasSon">
<rdfs:domain rdf:resource="&parenttrial;Parent"/>
<rdfs:range rdf:resource="&parenttrial;Son"/>
</owl:ObjectProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#hasAge -->
<owl:DatatypeProperty rdf:about="&parenttrial;hasAge"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#Parent -->
<owl:Class rdf:about="&parenttrial;Parent"/>
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#Son -->
<owl:Class rdf:about="&parenttrial;Son"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#JohnF -->
<owl:NamedIndividual rdf:about="&parenttrial;JohnF">
<rdf:type rdf:resource="&parenttrial;Parent"/>
<hasSon rdf:resource="&parenttrial;Son1"/>
<hasSon rdf:resource="&parenttrial;Son2"/>
<hasSon rdf:resource="&parenttrial;Son3"/>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#Son1 -->
<owl:NamedIndividual rdf:about="&parenttrial;Son1">
<rdf:type rdf:resource="&parenttrial;Son"/>
<hasAge rdf:datatype="&xsd;integer">3</hasAge>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#Son2 -->
<owl:NamedIndividual rdf:about="&parenttrial;Son2">
<rdf:type rdf:resource="&parenttrial;Son"/>
<hasAge rdf:datatype="&xsd;integer">4</hasAge>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/admin/ontologies/2015/7/parenttrial#Son3 -->
<owl:NamedIndividual rdf:about="&parenttrial;Son3">
<rdf:type rdf:resource="&parenttrial;Son"/>
<hasAge rdf:datatype="&xsd;integer">5</hasAge>
</owl:NamedIndividual>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->

Answer 1: There is no way through SWRL to check how many instances are connected to a certain property through SWRL. You are better off writing a sparql query with COUNT for this. Alternatively you can use an ontology framework and use an Iteratorto figure out the counts.
Answer 2: There is no way to loop a SWRL rule, perform an operation and return a value. SWRL rules are meant to add extra information about relations and not act as a programming language.
Solution: You are far better off using a ontology framework like Apache Jena or Owl api and writing a program to handle this instead of relying on SWRL. SWRL supports monotonic inferences only and thus cannot be used to loop over data in an ontology. Trying to do so will cause the rule to get executed infinitely.
Instead write a bit of code to do this. Refer to owl api or Jena ontology api and sparql in order to learn more on how to use these technologies.

Related

Consolibyte QuickBooks PHP Library - XML Validator Not Working

I have the following XML request to add a new Quickbooks bill:
<?xml version="1.0" encoding="utf-8"?>
<?qbposxml version="3.0"?>
<QBPOSXML>
<QBPOSXMLMsgsRq onError="stopOnError">
<BillAddRq>
<BillAdd defMacro="MACROTYPE"> <!-- required -->
<VendorRef> <!-- required -->
<ListID>80012448-1569211475</ListID> <!-- optional -->
</VendorRef>
<TxnDate>2019-06-28</TxnDate> <!-- optional -->
<DueDate>2019-06-29</DueDate> <!-- optional -->
<RefNumber>Ref12345</RefNumber> <!-- optional -->
<Memo>Memo12345</Memo> <!-- optional -->
<ExternalGUID>ExternalGUID12345</ExternalGUID> <!-- optional -->
<ExpenseLineAdd defMacro="MACROTYPE"> <!-- optional, may repeat -->
<AccountRef> <!-- optional -->
<FullName>Casual Labor:Moving</FullName> <!-- optional -->
</AccountRef>
<Amount>99.99</Amount> <!-- optional -->
<Memo>VillageMemo12345</Memo> <!-- optional -->
</ExpenseLineAdd>
</BillAdd>
</BillAddRq>
</QBPOSXMLMsgsRq>
</QBPOSXML>
Web connector is returning a 0x80040400: QuickBooks found an error when parsing the provided XML text stream. error with the above. I followed this post over at Intuit's support forums to try to use the built-in XML validator.
When I run my XML request through the validator, I get the following error:
How do I resolve the above validator error? Also, is there another way to validate QB XML other than using the built-in validator?
The platform choice you make in the validator, needs to match the platform choice you're targeting in your XML.
You're choosing to validate against:
QuickBooks (US Editions)
But your qbXML is for:
<?qbposxml version="3.0"?>
<QBPOSXML> (QuickBooks Point of Sale)
Since your validating against something that isn't your actual qbXML target, of course the validation is going to fail. It's invalid for what you've chosen.
If you're developing for Point of Sale, then validate against Point of Sale.
If you're developing for US editions of QuickBooks, then put in some qbXML for US versions of QuickBooks and validate that.

static mp3 song delayed starting with jplayer

I am trying to build a website that plays mp3. I am using:
jPlayer : For client side audio player.
icecast : For streaming mp3 audio.
Other technologies are ruby on rails, nginx, angularjs etc.
My Problem is:
jPlayer fully load the song then it start playing
So starting the song is always delayed based on song file size.
Other findings:
Byte rang request is working. But still loading the full song first.
My icecast.xml file is as following:
<icecast>
<!-- location and admin are two arbitrary strings that are e.g. visible
on the server info page of the icecast web interface
(server_version.xsl). -->
<location>Earth</location>
<admin>admin#playstore.com</admin>
<!-- IMPORTANT!
Especially for inexperienced users:
Start out by ONLY changing all passwords and restarting Icecast.
For detailed setup instructions please refer to the documentation.
It's also available here: http://icecast.org/docs/
-->
<limits>
<clients>100</clients>
<sources>2</sources>
<queue-size>2048</queue-size>
<client-timeout>30</client-timeout>
<header-timeout>15</header-timeout>
<source-timeout>10</source-timeout>
<!-- If enabled, this will provide a burst of data when a client
first connects, thereby significantly reducing the startup
time for listeners that do substantial buffering. However,
it also significantly increases latency between the source
client and listening client. For low-latency setups, you
might want to disable this. -->
<burst-on-connect>0</burst-on-connect>
<!-- same as burst-on-connect, but this allows for being more
specific on how much to burst. Most people won't need to
change from the default 64k. Applies to all mountpoints -->
<burst-size>512</burst-size>
</limits>
<authentication>
<!-- Sources log in with username 'source' -->
<source-password>irfan</source-password>
<!-- Relays log in with username 'relay' -->
<relay-password>passw0rd</relay-password>
<!-- Admin logs in with the username given below -->
<admin-user>admin</admin-user>
<admin-password>passw0rd</admin-password>
</authentication>
<!-- set the mountpoint for a shoutcast source to use, the default if not
specified is /stream but you can change it here if an alternative is
wanted or an extension is required
<shoutcast-mount>/live.nsv</shoutcast-mount>
-->
<!-- Uncomment this if you want directory listings -->
<!--
<directory>
<yp-url-timeout>15</yp-url-timeout>
<yp-url>http://dir.xiph.org/cgi-bin/yp-cgi</yp-url>
</directory>
-->
<!-- This is the hostname other people will use to connect to your server.
It affects mainly the urls generated by Icecast for playlists and yp
listings. You MUST configure it properly for YP listings to work!
-->
<hostname>localhost</hostname>
<!-- You may have multiple <listener> elements -->
<listen-socket>
<port>8000</port>
<bind-address>127.0.0.1</bind-address>
<shoutcast-mount>/stream</shoutcast-mount>
</listen-socket>
<!--
<listen-socket>
<port>8090</port>
</listen-socket>
-->
<!--
<listen-socket>
<port>8443</port>
<ssl>1</ssl>
</listen-socket>
-->
<!-- Global header settings
Headers defined here will be returned for every HTTP request to Icecast.
The ACAO header makes Icecast public content/API by default
This will make streams easier embeddable (some HTML5 functionality needs it).
Also it allows direct access to e.g. /status-json.xsl from other sites.
If you don't want this, comment out the following line or read up on CORS.
-->
<http-headers>
<header name="Access-Control-Allow-Origin" value="*" />
</http-headers>
<!-- Relaying
You don't need this if you only have one server.
Please refer to the config for a detailed explanation.
-->
<!--<master-server>127.0.0.1</master-server>-->
<!--<master-server-port>8001</master-server-port>-->
<!--<master-update-interval>120</master-update-interval>-->
<!--<master-password>hackme</master-password>-->
<!-- setting this makes all relays on-demand unless overridden, this is
useful for master relays which do not have <relay> definitions here.
The default is 0 -->
<!--<relays-on-demand>1</relays-on-demand>-->
<!--
<relay>
<server>127.0.0.1</server>
<port>8080</port>
<mount>/example.ogg</mount>
<local-mount>/different.ogg</local-mount>
<on-demand>0</on-demand>
<relay-shoutcast-metadata>0</relay-shoutcast-metadata>
</relay>
-->
<!-- Mountpoints
Only define <mount> sections if you want to use advanced options,
like alternative usernames or passwords
-->
<!-- Default settings for all mounts that don't have a specific <mount type="normal">.
-->
<!--
<mount type="default">
<public>0</public>
<intro>/server-wide-intro.ogg</intro>
<max-listener-duration>3600</max-listener-duration>
<authentication type="url">
<option name="mount_add" value="http://auth.example.org/stream_start.php"/>
</authentication>
<http-headers>
<header name="foo" value="bar" />
</http-headers>
</mount>
-->
<!-- Normal mounts -->
<!--
<mount type="normal">
<mount-name>/example-complex.ogg</mount-name>
<username>othersource</username>
<password>hackmemore</password>
<max-listeners>1</max-listeners>
<dump-file>/tmp/dump-example1.ogg</dump-file>
<burst-size>65536</burst-size>
<fallback-mount>/example2.ogg</fallback-mount>
<fallback-override>1</fallback-override>
<fallback-when-full>1</fallback-when-full>
<intro>/example_intro.ogg</intro>
<hidden>1</hidden>
<public>1</public>
<authentication type="htpasswd">
<option name="filename" value="myauth"/>
<option name="allow_duplicate_users" value="0"/>
</authentication>
<http-headers>
<header name="Access-Control-Allow-Origin" value="http://webplayer.example.org" />
<header name="baz" value="quux" />
</http-headers>
<on-connect>/home/icecast/bin/stream-start</on-connect>
<on-disconnect>/home/icecast/bin/stream-stop</on-disconnect>
</mount>
-->
<!--
<mount type="normal">
<mount-name>/auth_example.ogg</mount-name>
<authentication type="url">
<option name="mount_add" value="http://myauthserver.net/notify_mount.php"/>
<option name="mount_remove" value="http://myauthserver.net/notify_mount.php"/>
<option name="listener_add" value="http://myauthserver.net/notify_listener.php"/>
<option name="listener_remove" value="http://myauthserver.net/notify_listener.php"/>
<option name="headers" value="x-pragma,x-token"/>
<option name="header_prefix" value="ClientHeader."/>
</authentication>
</mount>
-->
<fileserve>1</fileserve>
<paths>
<!-- basedir is only used if chroot is enabled -->
<basedir>/usr/local/Cellar/icecast/2.4.2/share/icecast</basedir>
<!-- Note that if <chroot> is turned on below, these paths must both
be relative to the new root, not the original root -->
<logdir>/usr/local/Cellar/icecast/2.4.2/var/log/icecast</logdir>
<webroot>/usr/local/Cellar/icecast/2.4.2/share/icecast/web</webroot>
<adminroot>/usr/local/Cellar/icecast/2.4.2/share/icecast/admin</adminroot>
<!-- <pidfile>/usr/local/Cellar/icecast/2.4.2/share/icecast/icecast.pid</pidfile> -->
<!-- Aliases: treat requests for 'source' path as being for 'dest' path
May be made specific to a port or bound address using the "port"
and "bind-address" attributes.
-->
<!--
<alias source="/foo" destination="/bar"/>
-->
<!-- Aliases: can also be used for simple redirections as well,
this example will redirect all requests for http://server:port/ to
the status page
-->
<alias source="/" destination="/status.xsl"/>
<!-- The certificate file needs to contain both public and private part.
Both should be PEM encoded.
<ssl-certificate>/usr/local/Cellar/icecast/2.4.2/share/icecast/icecast.pem</ssl-certificate>
-->
</paths>
<logging>
<accesslog>access.log</accesslog>
<errorlog>error.log</errorlog>
<!-- <playlistlog>playlist.log</playlistlog> -->
<loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
<logsize>10000</logsize> <!-- Max size of a logfile -->
<!-- If logarchive is enabled (1), then when logsize is reached
the logfile will be moved to [error|access|playlist].log.DATESTAMP,
otherwise it will be moved to [error|access|playlist].log.old.
Default is non-archive mode (i.e. overwrite)
-->
<!-- <logarchive>1</logarchive> -->
</logging>
<security>
<chroot>0</chroot>
<!--
<changeowner>
<user>nobody</user>
<group>nogroup</group>
</changeowner>
-->
</security>
I need to understand how should I can do something that player will start playing the song after loading the very small amount of song to prevent starting delayed.
I finally solved it! I found chrome have the problem and it can't start an mp3 encoded music file while loading. But it can play immediately the other supported encoded music. Well this is not a permanent solution. But in my case, encoding all songs for fallback support gives me the trick. Now all major browsers are playing songs successfully.

How to insert nodes after specific node of an instance in Orbeon?

I have an instance in model:
<Exams>
<ExamCode>14</ExamCode>
</Exams>
<Exams>
<ExamCode>15</ExamCode>
</Exams>
I want to iterate on all elements and add after ExamCode element some nodes but without parent.
My instance after iterate should be like this:
<-- Wanted -->
<Exams>
<ExamCode>14</ExamCode>
<ExamTitle></ExamTitle>
<ExamDescription>/ExamDescription>
</Exams>
<Exams>
<ExamCode>15</ExamCode>
<ExamTitle></ExamTitle>
<ExamDescription></ExamDescription>
</Exams>
What i have tried is this:
Instance to add:
<!-- instance nodes to add-->
<xf:instance id="examRelatedNodes">
<ExamTitle/>
<ExamDescription/>
</xf:instance>
Adding "examRelatedNodes" instance to all repeated Exams nodes:
<!-- insert examRelatedNodes per Exam -->
<xf:action ev:event="xforms-ready" xxf:iterate="instance('fr-form-instance')/Exams">
<xf:insert context="." origin="instance('examRelatedNodes')"/>
</xf:action>
But I get an error that instance to add, should have parent!
I have read the documentation, this from the orbeon blog, but in all paradigms i find, the elements of to-add-instance have a parent, but in my case i don't want to have.Following these examples with parent node, i am able to add them, BUT with parent node "ParentOfExtraNodes" that i don't want:
<-- Not wanted -->
<Exams>
<ExamCode>14</ExamCode>
<ParentOfExtraNodes>
<ExamTitle></ExamTitle>
<ExamDescription>/ExamDescription>
<ParentOfExtraNodes/>
</Exams>
<Exams>
<ExamCode>15</ExamCode>
<ParentOfExtraNodes>
<ExamTitle></ExamTitle>
<ExamDescription>/ExamDescription>
<ParentOfExtraNodes/>
</Exams>
I am using Orbeon Forms 4.5 (XForms implementation).
What you are doing looks about right. But in your instance examRelatedNodes, you need to have a root element, say:
<xf:instance id="examRelatedNodes">
<RelatedNodes>
<ExamTitle/>
<ExamDescription/>
</RelatedNodes>
</xf:instance>
And then your insert will become:
<xf:insert context="." origin="instance('examRelatedNodes')/*"/>

Ant task to check that xml node exists in xml file

I have xml file inside that I want to add xml say
<car name="BMW">
<color>Red</color>
<model>x3</model>
</car>
I wish to check if node already exists then I want to update this otheriwse wanted to add new.
I am very new to ant xmltask so my question might be very simple.
With regards,
Avinash Nigam
using an additional root tag <foo></foo> for your example (needed for insert operation), with xmltask you may use =
<!-- edit file in place, use other dest if you need to create a new file -->
<xmltask source="path/to/file.xml" dest="path/to/file.xml">
<!-- create property if car node with name='BMW' exists -->
<copy path="//car[#name='BMW']/text()" property="modelexists"/>
<!-- insert new car node if car node with name='BMW' doesn't exist -->
<insert path="/foo" unless="modelexists">
<![CDATA[
<car name="BMW">
<color>Red</color>
<model>x3</model>
</car>
]]>
</insert>
<!-- replace car node if car node with name='BMW' exists -->
<replace path="//car[#name='BMW']" if="modelexists">
<![CDATA[
<car name="BMW">
<color>Blue</color>
<model>x4</model>
</car>
]]>
</replace>
</xmltask>

How to translate RDF graphs properties into OWL object properties?

I need to convert my RDF graph document into OWL (1 or 2) recognized by Protege 3.x. There is a W3C Recommendation for mapping OWL 2 Web Ontology Language Mapping to RDF Graphs which says that to declare Object Properties from RDF graphs one should add the rdf:type owl:ObjectProperty element. I have found problems for expressing OWL object properties with RDF graph formalisms in the following code:
<rdf:Property rdf:about="&uni;isTaughtBy">
<rdf:type rdf:resource="&owl;ObjectProperty"/>
<rdfs:domain rdf:resource="&uni;Course"/>
<rdfs:range rdf:resource="&uni;Proffessor"/>
</rdf:Property>
With the following specified namespaces:
xmlns:uni="http://www.mydomain.org/uni-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
Unfortunately, the upper mentioned code is not recognized and thus shown in the Protege 3.x IDE.
The following code is readable by Protege 4 (recommended version). Copy paste the block and save it in a new file, you should then be able to read it with Protege:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY uni-ns "http://www.mydomain.org/uni-ns#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www.mydomain.org/uni-ns#"
xml:base="http://www.mydomain.org/uni-ns"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:uni-ns="http://www.mydomain.org/uni-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://www.mydomain.org/uni-ns#"/>
<owl:ObjectProperty rdf:about="&uni-ns;isTaughtBy">
<rdfs:domain rdf:resource="&uni-ns;Course"/>
<rdfs:range rdf:resource="&uni-ns;Professor"/>
</owl:ObjectProperty>
<owl:Class rdf:about="&uni-ns;Course"/>
<owl:Class rdf:about="&uni-ns;Professor">
<rdfs:subClassOf rdf:resource="&owl;Thing"/>
</owl:Class>
</rdf:RDF>

Resources