I want to know How to parse the file in OWL/XML syntax - semantic-web

I don't know how to parse this file, can someone tell me how to parse it?
The file is on the below. I have tried to find the way to parse for about 3 days.
<?xml version="1.0"?>
<!DOCTYPE Ontology [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY ontology_people1 "http://www.okkam.org/ontology_people1.owl#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2006/12/owl2-xml#"
xml:base="http://www.w3.org/2006/12/owl2-xml#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
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#"
xmlns:ontology_people1="http://www.okkam.org/ontology_people1.owl#"
URI="http://www.okkam.org/ontology_people1.owl">
<SubClassOf>
<Class URI="&ontology_people1;Address"/>
<Class URI="&ontology_people1;Location"/>
</SubClassOf>
<Declaration>
<Class URI="&ontology_people1;Address"/>
</Declaration>
......
</Ontology>
<!-- Generated by the OWL API (version 2.2.1.1138) http://owlapi.sourceforge.net -->

This can be parsed with the default parsers loaded by OWLAPI.
This should be enough:
import java.io.File;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class Check {
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
OWLOntology o=manager.loadOntologyFromOntologyDocument(new File("filename.xml"));
}
}

Don't get frustrated. I think you are looking for an xml parser. Which language are you using? There are already many xml parser implemented by other people. Here is an example using Java: https://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

Related

Is there a way to query using SPARQL for more than one value of object when the subject and predicate are the same?

For context I am using GraphDB (SPARQL 1.1), and I have extended the What To Make ontology. I'd like to construct a query that can select ONLY the subjects that contain all of the objects with matching values for a particular predicate.
In my data (below) selecting the individual &so;KitchenDrawer's so:contains predicates and matching those against only those '&wtm;Recipe''s that contain just the values for wtm:hasIngredient. The subject and predicate are the same but there are alternating objects.
When I run the query (with &so;KitchenDrawer only containing &ind;Basil and &ind;Tomato), I would like to only get the subject's &ind;JustTomatoAndBasil and &ind;JustTomato, omitting &ind;Pesto as it has ingredients other than basil and tomato.
RDF Data:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY dct "http://purl.org/dc/terms/" >
<!ENTITY obo "http://purl.obolibrary.org/obo/" >
<!ENTITY skos "http://www.w3.org/2004/02/skos/core#" >
<!ENTITY wtm "http://purl.org/heals/food/" >
<!ENTITY ind "http://purl.org/heals/ingredient/" >
<!ENTITY prov "http://www.w3.org/ns/prov#">
<!ENTITY sm "http://www.omg.org/techprocess/ab/SpecificationMetadata/">
<!ENTITY so "http://example.com/storage-ontology/">
]>
<rdf:RDF xml:base="http://purl.org/heals/ingredient/"
xmlns:so="http://example.com/storage-ontology/"
xmlns:wtm="http://purl.org/heals/food/"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:prov="http://www.w3.org/ns/prov#"
xmlns:ind="http://purl.org/heals/ingredient/"
xmlns:sm="https://www.omg.org/techprocess/ab/SpecificationMetadata/">
<owl:Ontology rdf:about="http://purl.org/heals/ingredient/">
<owl:imports rdf:resource="http://purl.org/heals/food/"/>
<owl:imports rdf:resource="http://www.omg.org/techprocess/ab/SpecificationMetadata/"/>
<rdfs:label>What to Make Individuals Extensions</rdfs:label>
<dct:license rdf:datatype="&xsd;anyURI">http://opensource.org/licenses/MIT</dct:license>
</owl:Ontology>
<owl:NamedIndividual rdf:about="&ind;JustTomato">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Tomato"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&ind;JustTomatoAndBasil">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Tomato"/>
<wtm:hasIngredient rdf:resource="&ind;Basil"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&ind;Pesto">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Basil"/>
<wtm:hasIngredient rdf:resource="&ind;PineNuts"/>
<wtm:hasIngredient rdf:resource="&ind;Parmesan"/>
<wtm:hasIngredient rdf:resource="&ind;Garlic"/>
<wtm:hasIngredient rdf:resource="&ind;OliveOil"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<wtm:serves rdf:datatype="&xsd;integer">4</wtm:serves>
<rdfs:label>basil pesto</rdfs:label>
<skos:definition>a traditional pesto made from paresan cheese and basil</skos:definition>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:Class rdf:about="&so;StorageLocation">
</owl:Class>
<owl:Class rdf:about="&so;Drawer">
<rdfs:subClassOf rdf:resource="&so;StorageLocation"/>
</owl:Class>
<owl:ObjectProperty rdf:about="&so;contains">
</owl:ObjectProperty>
<owl:NamedIndividual rdf:about="&so;KitchenDrawer">
<rdf:type rdf:resource="&so;Rack"/>
<so:contains rdf:resource="&ind;Basil"></so:contains>
<so:contains rdf:resource="&ind;Tomato"></so:contains>
</owl:NamedIndividual>
</rdf:RDF>

Error when calling dependency of one method of another class into other class in TestNG automation

I want to add dependency of one test method from class A to another testMethod in class B.
Whenever I am running method "testTwo()" from class B I am getting error as
"method B.testTwo() depends on nonexistent group A.Group1" , my class structure is as below .
public class A
{
#Test(groups={"A.Group1"})
public void testOne(){}
}
public class B
{
#Test(dependsOnGroups={"A.Group1"})
public void testTwo(){}
}
Can anyone please guide here ?,
also My test.xml looks like below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TEST-AUTOMATION" thread-count="1"
preserve-order="true" data-provider-thread-count="1">
<test name="TESTS">
<classes>
<class name="A"/>
<class name="B"/>
</classes>
</test>
</suite>

Magento 2 change pdf filename

I want to change the filenames of the PDF files in Magento 2.
The default names are not clear and I want invoices to be searchable when saved to a location on my pc.
Is it possible to change the filenames of the PDF-files in Magento 2 to a format like "invoice_1000000123.pdf"?
You should never edit core files. Seriously, don't.
Since /vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php is an abstract class you have to use a plugin or preference in your module in order to override it.
What you need to achieve that:
The usual minimum files:
/Vendor/Module/composer.json, /Vendor/Module/registration.php, /Vendor/Module/etc/module.xml
In /Vendor/Module/etc/module.xml you should sequence Magento_Sales
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
Then you can either use a plugin or a preference in /Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction" type="Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction"/>
</config>
Plugin would look something like this:
<type name="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction">
<plugin name="Vendor_Module::aroundPrintInvoice" type="Vendor\Module\Block\Class" sortOrder="0"/>
</type>
Now add a PrintAction.php to the path specified in your preference / plugin (Example for preference)
<?php
namespace Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice;
class PrintAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction
{
/* Write code here */
}
You need override the invoice admin controller.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="\Magento\Sales\Controller\Adminhtml\Order\Invoice"
type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>
In your custom module admin controller, You need to change the name of Pdf file.
public function execute()
{
$invoiceId = $this->getRequest()->getParam('invoice_id');
return $this->_fileFactory->create(
'invoice_13012020' . $invoiceId . '.pdf', //<== Change the pdf name here.
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
...
}
Reference Link
Yes it is possible to change invoice pdf filename.
Please go to following path:
/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
You can change filename from above file.

TestNG - Run each instance from TestNG factory as separate test

I am using TestNG for test automation along with ReportNG for reporting. I use a TestNG factory class to provide different inputs for my tests. The problem which I face here is that all test instances supplied by the factory run under the same test, and the report generated displays all the scenarios under a single test.
I want to run each test instance supplied by the factory as a separate test. Is there any way to do this? PFB my xml configuration
<suite name="Default suite" parallel="classes">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
</listeners>
<test verbose="2" name="Default test" group-by-instances="true">
<classes>
<class name="com.test.factory.RAExcelFactory"/>
</classes>
</test> <!-- Default test -->
</suite> <!-- Default suite -->
No this is not possible currently in TestNG.
Alternately you can consider doing the following instead of using a factory.
Upgrade to latest TestNG version
Build an implementation of org.testng.IAlterSuiteListener and within it include logic to construct multiple <test> tags by using whatever logic you have within your Factory (am guessing it leverages a data driven mechanism)
Something like below
Test Class
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class StudentTest {
private int age;
#BeforeClass
#Parameters("age")
public void setup(int age) {
this.age = age;
}
#Test
public void firstTest() {
Assert.assertTrue(age >=0);
}
#Test(dependsOnMethods = "firstTest")
public void secondTest() {
Assert.assertTrue(age <= 125);
}
}
An IAlterSuiteListener implementation
import org.testng.IAlterSuiteListener;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.util.ArrayList;
import java.util.List;
public class SuiteAlteringListener implements IAlterSuiteListener {
#Override
public void alter(List<XmlSuite> suites) {
for (XmlSuite suite : suites) {
List<XmlTest> tests = new ArrayList<>();
Integer[] datum = getData();
for (Integer data : datum) {
XmlTest test = new XmlTest(suite);
test.setName("test_" + data);
test.addParameter("age", Integer.toString(data));
test.getClasses().add(new XmlClass(StudentTest.class));
}
}
}
private Integer[] getData() {
//Change this to your data provider implementation
return new Integer[]{
1, 2, 3
};
}
}
The suite xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="my_suite" parallel="false" verbose="3">
<listeners>
<listener class-name="com.rationaleemotions.stackoverflow.SuiteAlteringListener"/>
</listeners>
</suite>
and here's how the testng-results.xml looks like (The other reports would have similar details as well). I am just choosing to attach the easiest representation.
<?xml version="1.0" encoding="UTF-8"?>
<testng-results skipped="0" failed="0" ignored="0" total="6" passed="6">
<reporter-output>
</reporter-output>
<suite name="my_suite" duration-ms="10077" started-at="2017-05-27T07:49:36Z" finished-at="2017-05-27T07:49:46Z">
<groups>
</groups>
<test name="test_1" duration-ms="24" started-at="2017-05-27T07:49:36Z" finished-at="2017-05-27T07:49:36Z">
<class name="com.rationaleemotions.stackoverflow.StudentTest">
<test-method status="PASS" signature="setup(int)[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#61dc03ce]" name="setup" is-config="true" duration-ms="8" started-at="2017-05-27T13:19:36Z" finished-at="2017-05-27T13:19:36Z">
<params>
<param index="0">
<value>
<![CDATA[1]]>
</value>
</param>
</params>
<reporter-output>
</reporter-output>
</test-method> <!-- setup -->
<test-method status="PASS" signature="firstTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#61dc03ce]" name="firstTest" duration-ms="2" started-at="2017-05-27T13:19:36Z" finished-at="2017-05-27T13:19:36Z">
<reporter-output>
</reporter-output>
</test-method> <!-- firstTest -->
<test-method status="PASS" signature="secondTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#61dc03ce]" name="secondTest" duration-ms="1" started-at="2017-05-27T13:19:36Z" depends-on-methods="com.rationaleemotions.stackoverflow.StudentTest.firstTest" finished-at="2017-05-27T13:19:36Z">
<reporter-output>
</reporter-output>
</test-method> <!-- secondTest -->
</class> <!-- com.rationaleemotions.stackoverflow.StudentTest -->
</test> <!-- test_1 -->
<test name="test_2" duration-ms="2" started-at="2017-05-27T07:49:41Z" finished-at="2017-05-27T07:49:41Z">
<class name="com.rationaleemotions.stackoverflow.StudentTest">
<test-method status="PASS" signature="setup(int)[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#458ad742]" name="setup" is-config="true" duration-ms="0" started-at="2017-05-27T13:19:41Z" finished-at="2017-05-27T13:19:41Z">
<params>
<param index="0">
<value>
<![CDATA[2]]>
</value>
</param>
</params>
<reporter-output>
</reporter-output>
</test-method> <!-- setup -->
<test-method status="PASS" signature="firstTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#458ad742]" name="firstTest" duration-ms="0" started-at="2017-05-27T13:19:41Z" finished-at="2017-05-27T13:19:41Z">
<reporter-output>
</reporter-output>
</test-method> <!-- firstTest -->
<test-method status="PASS" signature="secondTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#458ad742]" name="secondTest" duration-ms="0" started-at="2017-05-27T13:19:41Z" depends-on-methods="com.rationaleemotions.stackoverflow.StudentTest.firstTest" finished-at="2017-05-27T13:19:41Z">
<reporter-output>
</reporter-output>
</test-method> <!-- secondTest -->
</class> <!-- com.rationaleemotions.stackoverflow.StudentTest -->
</test> <!-- test_2 -->
<test name="test_3" duration-ms="2" started-at="2017-05-27T07:49:46Z" finished-at="2017-05-27T07:49:46Z">
<class name="com.rationaleemotions.stackoverflow.StudentTest">
<test-method status="PASS" signature="setup(int)[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#66d2e7d9]" name="setup" is-config="true" duration-ms="0" started-at="2017-05-27T13:19:46Z" finished-at="2017-05-27T13:19:46Z">
<params>
<param index="0">
<value>
<![CDATA[3]]>
</value>
</param>
</params>
<reporter-output>
</reporter-output>
</test-method> <!-- setup -->
<test-method status="PASS" signature="firstTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#66d2e7d9]" name="firstTest" duration-ms="0" started-at="2017-05-27T13:19:46Z" finished-at="2017-05-27T13:19:46Z">
<reporter-output>
</reporter-output>
</test-method> <!-- firstTest -->
<test-method status="PASS" signature="secondTest()[pri:0, instance:com.rationaleemotions.stackoverflow.StudentTest#66d2e7d9]" name="secondTest" duration-ms="0" started-at="2017-05-27T13:19:46Z" depends-on-methods="com.rationaleemotions.stackoverflow.StudentTest.firstTest" finished-at="2017-05-27T13:19:46Z">
<reporter-output>
</reporter-output>
</test-method> <!-- secondTest -->
</class> <!-- com.rationaleemotions.stackoverflow.StudentTest -->
</test> <!-- test_3 -->
</suite> <!-- my_suite -->
</testng-results>
Would this work for you ?

magento event observer (magento1.7)

i am trying to implement an simple observer in my module (app/code/local/Foo/Bar).
My objective is to set the product names to '[product name] is cool' when a product is loaded in the frontend.
These are my files:
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
</global>
<frontend>
<events>
<catalog_product_load_after>
<observers>
<foo_bar>
<type>model</type>
<class>foo_bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
</observers>
</catalog_product_load_after>
</events>
</frontend>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer{
public function catalogProductLoadAfter(Varien_Event_Observer $observer)
{
$product = $observer ->getProduct();
$product ->setName($product.getName().' '.'is cool');
}
}
?>
And i have also configured the module in app/etc/modules/Foo_Bar.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
But it doenst work, does anyone have any suggestion?
You only need to module name for the model:
<foo_bar>
<type>model</type>
<class>bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
you don't need to specify Foo_Bar
also have you an error in your PHP
$product ->setName($product.getName().' '.'is cool');
should be
$product->setName($product->getName().' '.'is cool');