I want to express this relation: if article X has author Y, and the author has the influenceFactor medium or high(3 classes: low , medium, high) then this article is regarded as highly recommended.
(?x computer-science#hasAuthor ?y)(?y computer-science#hasInfluenceFactor computer-science#High) -> (?x computer-science#isImportant computer-science#importantfactor)
is my thought right?
here is some snippet of the ontology
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor">
<rdf:type rdf:resource="&owl;TransitiveProperty"/>
<owl:propertyDisjointWith rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#isAuthorOf"/>
<rdfs:range>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#author"/>
</owl:Restriction>
</rdfs:range>
<rdfs:domain>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
</owl:Restriction>
</rdfs:domain>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor">
<rdf:type rdf:resource="&owl;TransitiveProperty"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#author"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:ObjectProperty>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#High">
<rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:NamedIndividual>
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#isImportant">
<rdf:type rdf:resource="&owl;TransitiveProperty"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:ObjectProperty>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor">
<rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor"/>
</owl:NamedIndividual>
sincere thanks to any viewer of my question :)
You don't need to create a rule to express your ontology, you can do it entirely in OWL. First we define an ontology based on your example, but with some new axioms. In particular, we define two new class expressions: InfluentialArticle and ImportantArticle. An influential article has high or medium impact, an important author wrote at least one influential article:
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix owl: <http://www.w3.org/2002/07/owl#>.
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
#prefix cs: <http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#>.
# properties
cs:hasAuthor
a owl:ObjectProperty ;
rdfs:domain cs:Article ;
rdfs:range cs:Author .
cs:wrote
a owl:ObjectPropert ;
owl:inverseOf cs:hasAuthor .
# classes
cs:hasInfluenceFactor
a owl:ObjectProperty ;
rdfs:domain cs:Article ;
rdfs:range cs:InfluenceFactor .
cs:InfluenceFactor
owl:equivalentClass
[a owl:Class ;
owl:oneOf ( cs:high cs:medium cs:low )
].
cs:Author a owl:Class.
cs:Article a owl:Class.
# axioms
# an influential article has a high or medium impact
cs:InfluentialArticle
rdfs:subClassOf cs:Article ;
owl:equivalentClass [
owl:unionOf (
[a owl:Restriction ;
owl:onProperty cs:hasInfluenceFactor ;
owl:hasValue cs:high]
[a owl:Restriction ;
owl:onProperty cs:hasInfluenceFactor ;
owl:hasValue cs:medium
]
)
].
# an important author wrote an influential article
cs:ImportantAuthor
rdfs:subClassOf cs:Author ;
owl:equivalentClass [
a owl:Restriction ;
owl:onProperty cs:wrote ;
owl:someValuesFrom cs:InfluentialArticle
].
# individuals
# fred wrote a lousy paper
cs:fred
a cs:Author.
cs:article1
a cs:Article ;
cs:hasInfluenceFactor cs:low ;
cs:hasAuthor cs:fred.
# jane wrote a good paper
cs:jane
a cs:Author.
cs:article2
a cs:Article ;
cs:hasInfluenceFactor cs:high ;
cs:hasAuthor cs:jane.
Now we can write some Jena code to load this ontology and process it with a built-in reasoner:
package examples;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class ReasonerExample
{
String NS = "http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#";
public static void main( String[] args ) {
new ReasonerExample().run();
}
public void run() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
FileManager.get().readModel( m, "src/main/resources/comp-sci.ttl" );
// list all authors
System.out.println( "All authors:" );
OntClass author = m.getOntClass( NS + "Author" );
for (Iterator<? extends OntResource> i = author.listInstances(); i.hasNext(); ) {
System.out.println( " " + i.next().getURI() );
}
// list high impact authors
OntClass importantAuthor = m.getOntClass( NS + "ImportantAuthor" );
System.out.println( "Important authors:" );
for (Iterator<? extends OntResource> i = importantAuthor.listInstances(); i.hasNext(); ) {
System.out.println( " " + i.next().getURI() );
}
}
}
Which gives the following output:
All authors:
http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane
http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#fred
Important authors:
http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane
Note I also fixed your names to use OWL conventions: leading capital letter for classes, lower case for everything else. I also simplified the domain and range constraints, which were a bit weird.
Update
Following a comment from the original poster, I translated the ontology to RDF/XML using Jena's rdfcat tool as follows:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cs="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
<owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor">
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor">
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
<rdfs:range>
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#InfluenceFactor">
<owl:equivalentClass>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#medium"/>
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#low"/>
</owl:oneOf>
</owl:Class>
</owl:equivalentClass>
</rdf:Description>
</rdfs:range>
</owl:ObjectProperty>
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#ImportantAuthor">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectPropert rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#wrote">
<owl:inverseOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
</owl:ObjectPropert>
</owl:onProperty>
<owl:someValuesFrom>
<rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#InfluentialArticle">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
<owl:equivalentClass rdf:parseType="Resource">
<owl:unionOf rdf:parseType="Collection">
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor"/>
<owl:hasValue rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor"/>
<owl:hasValue rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#medium"/>
</owl:Restriction>
</owl:unionOf>
</owl:equivalentClass>
</rdf:Description>
</owl:someValuesFrom>
</owl:Restriction>
</owl:equivalentClass>
</rdf:Description>
<cs:Article rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article2">
<cs:hasInfluenceFactor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
<cs:hasAuthor>
<cs:Author rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane"/>
</cs:hasAuthor>
</cs:Article>
<cs:Article rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article1">
<cs:hasInfluenceFactor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#low"/>
<cs:hasAuthor>
<cs:Author rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#fred"/>
</cs:hasAuthor>
</cs:Article>
</rdf:RDF>
Related
As a complete newbie (but learning fast), I've been studying through Elmish.wpf but it is unclear to me how to manage a TabControl placed on a TabItem of another TabControl. For example, in Xaml, the top level window is:
<Window x:Class="FrontOffice.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FrontOffice"
xmlns:doctor="clr-namespace:Doctor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Window.Resources>
<DataTemplate x:Key="DoctorViewTemplate">
<doctor:DoctorView />
</DataTemplate>
<DataTemplate x:Key="NurseViewTemplate">
<local:NurseView/>
</DataTemplate>
<DataTemplate x:Key="MedicalRecordsViewTemplate">
<local:MedicalRecordsView/>
</DataTemplate>
<DataTemplate x:Key="PatientViewTemplate">
<local:PatientView/>
</DataTemplate>
<DataTemplate x:Key="ProvidersViewTemplate">
<local:ProvidersView/>
</DataTemplate>
<local:PropertyDataTemplateSelector x:Key="templateSelector"
DoctorViewTemplate="{StaticResource DoctorViewTemplate}"
NurseViewTemplate="{StaticResource NurseViewTemplate}"
MedicalRecordsViewTemplate="{StaticResource MedicalRecordsViewTemplate}"
PatientViewTemplate="{StaticResource PatientViewTemplate}"
ProvidersViewTemplate="{StaticResource ProvidersViewTemplate}"/>
</Window.Resources>
<Grid>
<TabControl ItemsSource="{Binding Tabs}" ContentTemplateSelector="{StaticResource templateSelector}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
</Window>
Each of the views: DoctorView, NurseView, MedicalRecordsView, etc.., have thier own tab control similar to this (but with different views and properties):
<UserControl x:Class="Doctor.DoctorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Doctor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<DataTemplate x:Key="AppointmentsViewTemplate">
<local:AppointmentsView />
</DataTemplate>
<DataTemplate x:Key="ChartStatusViewTemplate">
<local:ChartStatusView/>
</DataTemplate>
<DataTemplate x:Key="CheckInViewTemplate">
<local:CheckInView/>
</DataTemplate>
<local:PropertyDataTemplateSelector x:Key="templateSelector"
AppointmentsViewTemplate="{StaticResource AppointmentsViewTemplate}"
ChartStatusViewTemplate="{StaticResource ChartStatusViewTemplate}"
CheckInViewTemplate="{StaticResource CheckInViewTemplate}"/>
</UserControl.Resources>
<Grid>
<TabControl ItemsSource="{Binding Tabs}" ContentTemplateSelector="{StaticResource templateSelector}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
</UserControl>
The Top Most Window in F# is currently defined as:
namespace FrontOfficeModels
open Elmish.WPF
open Elmish
module FrontOffice =
type DetailType =
| DoctorView
| NurseView
| MedicalRecordsView
| PatientView
| ProviderView
type Tab = { Id: int; Header: string; Type: DetailType }
type Model =
{ Tabs: Tab list
Selected: int option }
type Msg =
| Select of int option
let init () =
{ Tabs = [{Id=0; Header="Doctor View"; Type=DoctorView}
{Id=1; Header="Nurse View"; Type=NurseView}
{Id=2; Header="Medical Records View"; Type=MedicalRecordsView}
{Id=3; Header="Patient View"; Type=PatientView}
{Id=4; Header="Provider View"; Type=ProviderView }
]
Selected = Some 3 }
let update msg m =
match msg with
| Select entityId -> { m with Selected = entityId }
let bindings () : Binding<Model, Msg> list = [
"Tabs" |> Binding.oneWay (fun m -> m.Tabs)
]
let designVm = ViewModel.designInstance (init ()) (bindings ())
let main window =
Program.mkSimpleWpf init update bindings
|> Program.withConsoleTrace
|> Program.runWindowWithConfig
{ ElmConfig.Default with LogConsole = true; Measure = true }
window
Now, I'm thinking I need to change DoctorView, NurseView, etc... in the DetailType to be separate models -- since each will now have its own tab control and completely different properties for data entry,
type DetailType =
| DoctorView
| NurseView
| MedicalRecordsView
| PatientView
| ProviderView
and I'm thinking that I need to use Elmish.WPF Bindings.SubModel. But if I do so, how then is the Binding for the top window rewritten? How is this best done?
Thanks for any help with this.
TIA
OP cross posted in this GitHub issue and I answered their question in this comment.
This is my code that works as recognizer. This works.
s --> v(X), v(X), c(Y).
s --> v(X), c(Y), c(X).
v(quiet) --> line(quiet).
v(loud) --> line(loud).
c(quiet) --> line(quiet).
c(loud) --> line(loud).
line(quiet) --> ['laa!'].
line(loud) --> ['LAA!'].
But then I am trying to work this code for a parser
s(s(X,X,Y)) --> v(X), v(X), c(Y).
s(s(X,Y,X)) --> v(X), c(Y), c(X).
v(quiet,v(quiet)) --> line(quiet).
v(loud, v(loud)) --> line(loud).
c(quiet, c(quiet)) --> line(quiet).
c(loud, c(loud)) --> line(loud).
line(quiet, line('laa!')) --> ['laa!'].
line(loud , line('LAA!')) --> ['LAA!'].
I am not sure what is the right ways to change arguments so that the recognizer works as a parser as well. Can anyone guide me how do we change arguments so it works as a parser.
I think you were already 90% of the way there with your original code. I don't know what you want to parse to, so I came up with this:
s(xxy(X,Y)) --> v(X), v(X), c(Y).
s(xyx(X,Y)) --> v(X), c(Y), c(X).
v(quiet) --> line(quiet).
v(loud) --> line(loud).
c(quiet) --> line(quiet).
c(loud) --> line(loud).
line(quiet) --> ['laa!'].
line(loud) --> ['LAA!'].
As you can see, the only material change here is changing s//0 to s//1 and returning something with the X and Y variables (which were previously singletons anyway). An example of using it to parse all your sentences is:
?- phrase(s(Parse), Sentence).
Parse = xxy(quiet, quiet),
Sentence = ['laa!', 'laa!', 'laa!'] ;
Parse = xxy(quiet, loud),
Sentence = ['laa!', 'laa!', 'LAA!'] ;
Parse = xxy(loud, quiet),
Sentence = ['LAA!', 'LAA!', 'laa!'] ;
Parse = xxy(loud, loud),
Sentence = ['LAA!', 'LAA!', 'LAA!'] ;
Parse = xyx(quiet, quiet),
Sentence = ['laa!', 'laa!', 'laa!'] ;
Parse = xyx(quiet, loud),
Sentence = ['laa!', 'LAA!', 'laa!'] ;
Parse = xyx(loud, quiet),
Sentence = ['LAA!', 'laa!', 'LAA!'] ;
Parse = xyx(loud, loud),
Sentence = ['LAA!', 'LAA!', 'LAA!'].
To give you more help I'd probably have to know more about the intermediate representation you want to obtain, but hopefully this will illustrate the idea. You were so close already!
I define an assembler file with name dataset2.ttl. The content of this file is:
#prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset .
tdb:GraphTDB rdfs:subClassOf ja:Model .
<#dataset> rdf:type tdb:DatasetTDB ;
tdb:location "DB" ;
tdb:unionDefaultGraph true ;
.
<#data1> rdf:type tdb:GraphTDB ;
tdb:dataset <#dataset> ;
tdb:graphName <http://example.org/data1> ;
ja:content [ja:externalContent <file:///C:/Users/data/data1.ttl>;];
.
The related jena code to create a datase is:
public class TDB {
public static void main(String[] args) {
Dataset ds = null;
try {
ds = TDBFactory.assembleDataset("Dataset2.ttl");
if(ds == null) {
System.out.println("initial tdb failed");
} else {
System.out.println("Default Model:");
Model model = ds.getDefaultModel();
ds.begin(ReadWrite.WRITE);
model.write(System.out, "TURTLE");
}
} finally {
if(ds != null) {
ds.close();
}
}
}
The content in data1.ttl is:
#prefix : <http://example.org/> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
:alice
a foaf:Person ;
foaf:name "Alice" ;
foaf:mbox <mailto:alice#example.org> ;
foaf:knows :bob ;
foaf:knows :charlie ;
foaf:knows :snoopy ;
.
:bob
foaf:name "Bob" ;
foaf:knows :charlie ;
.
:charlie
foaf:name "Charlie" ;
foaf:knows :alice ;
.
A dataset has been created using this code. However, the content in the file of "data1.ttl" has not been read into the model. What is the problem of my code?
You also have
<#dataset> rdf:type tdb:DatasetTDB ;
tdb:location "DB" ;
tdb:unionDefaultGraph true ;
.
and
ds = TDBFactory.assembleDataset("Dataset2.ttl");
so you are asking Jena to assemble a dataset. That dataset will be <#dataset> (find by the type). It is not connected the graph you define so that's ignored; you can remove that part. Assembling the dataset is the way to do this.
You have tdb:unionDefaultGraph true so the default graph for query is the combination of all named graphs in the dataset.
Pick one out with model.getNamedModel.
If you use SPARQL, use the GRAPH keyword.
I would try validating your ttl file online to make sure they dataset2.ttl and data.ttl are both valid. I noticed you seem to add an extra semi-colon at the end when it's not needed (it should end with just a period).
try changing your line to this:
ja:content [ja:externalContent <file:///C:/Users/data/data1.ttl>] .
<#data1> rdf:type tdb:GraphTDB ;
tdb:dataset <#dataset> ;
tdb:graphName <http://example.org/data1> ;
ja:content [ja:externalContent <file:///C:/Users/data/data1.ttl>;];
.
Note the tdb:GraphTDB which means attach to a graph in the database. It does not load data with ja:content.
As a persistent store, it is expected that the data is already loaded, e.g.by tdbloader, not every time the assembler is used.
I intend to add object properties to classes using Jena API.
I can't find a proper way how to do this. I would like to achieve something similar to what can be done in Protege:
ExampleObjectProperty is my own ObjectProperty.
I tried adding this property using ontClass.addProperty, also adding a new statement to ontModel, but the result wasn't the same.
As far as I know, in Protege, blank node is generated (saying that :blank_node has some onProperty ExampleObjectProperty and ExampleClass has someValuesOf :blank_node... I'm not sure about this though).
loopasam's comment is correct; you're not trying to "add a property to a class" or anything like that. What you're trying to do is add a subclass axiom. In the Manchester OWL syntax, it would look more or less like:
ExampleResource subClassOf (ExampleObjectProperty some ExampleClass)
Jena's OntModel API makes it pretty easy to create that kind of axiom though. Here's how you can do it:
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class SubclassOfRestriction {
public static void main(String[] args) {
final String NS = "https://stackoverflow.com/q/20476826/";
final OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );
// Create the two classes and the property that we'll use.
final OntClass ec = model.createClass( NS+"ExampleClass" );
final OntClass er = model.createClass( NS+"ExampleResource" );
final OntProperty eop = model.createOntProperty( NS+"ExampleObjectProperty" );
// addSuperClass and createSomeValuesFromRestriction should be pretty straight-
// forward, especially if you look at the argument names in the Javadoc. The
// null just indicates that the restriction class will be anonymous; it doesn't
// have an URI of its own.
er.addSuperClass( model.createSomeValuesFromRestriction( null, eop, ec ));
// Write the model.
model.write( System.out, "RDF/XML-ABBREV" );
model.write( System.out, "TTL" );
}
}
The output is:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Class rdf:about="https://stackoverflow.com/q/20476826/ExampleResource">
<rdfs:subClassOf>
<owl:Restriction>
<owl:someValuesFrom>
<owl:Class rdf:about="https://stackoverflow.com/q/20476826/ExampleClass"/>
</owl:someValuesFrom>
<owl:onProperty>
<rdf:Property rdf:about="https://stackoverflow.com/q/20476826/ExampleObjectProperty"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
</rdf:RDF>
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<https://stackoverflow.com/q/20476826/ExampleObjectProperty>
a rdf:Property .
<https://stackoverflow.com/q/20476826/ExampleClass>
a owl:Class .
<https://stackoverflow.com/q/20476826/ExampleResource>
a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty <https://stackoverflow.com/q/20476826/ExampleObjectProperty> ;
owl:someValuesFrom <https://stackoverflow.com/q/20476826/ExampleClass>
] .
In Protégé that appears as follows:
] .
I'm adding few resources and properties in a Model like this:
String xyz = "http://www.example.com/xyz";
String creator = "http://www.example.com/Harry";
String email = "http://www.example.com/harry#xyz.com";
Resource creat = m.createResource(creator);
Resource eId = m.createResource(email);
Resource res = m.createResource(xyz).addProperty(DC.creator,creat.addProperty(VCARD.EMAIL, eId));
m.write(System.out);
I'm getting this as a result:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
xmlns:dc="http://purl.org/dc/elements/1.1/" >
<rdf:Description rdf:about="http://www.example.com/xyz">
<dc:creator rdf:resource="http://www.example.com/Harry"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.com/Harry">
<vcard:EMAIL rdf:resource="http://www.example.com/harry#xyz.com"/>
</rdf:Description>
</rdf:RDF>
Is there any other way by which I can get the result Like:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
xmlns:dc="http://purl.org/dc/elements/1.1/" >
<rdf:Description rdf:about="http://www.example.com/xyz">
<dc:creator rdf:resource="http://www.example.com/Harry"/>
<vcard:EMAIL rdf:resource="http://www.example.com/harry#xyz.com"/>
</rdf:Description>
</rdf:RDF>
Try the RDF/XML pretty writer: Use
model.write( .... , "RDF/XML_ABBREV")
or use Turtle.