I have my class Alert which contain as individual
Alert_1
Alert_2
Alert_3
and each individual has properties witch contains values
for example
Alert_1 :
hasanalyser : analyser546
hastime: 10
hasdatainfo: difficult
I can now get all individuals but I can not get those (hasanalyser, hastime and hasdatainfo) values
Here is my code and it works. How I can get what I want please?
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/base_connaissance.owl");
OntModel model = owlModel.getOntModel();
OWLNamedClass theAlert = owlModel.getOWLNamedClass("Alert");
Collection CAlerte = theAlert.getInstances();
int nombreAlerte =CAlerte.size();
String[ ] list_alerte=new String[ nombreAlerte ];
OWLIndividual[ ] idorg=(OWLIndividual[ ]) CAlerte.toArray(new OWLIndividual[ 0 ]);
for(int j=0;j< nombreAlerte;j++){
list_alerte[ j ]=idorg[ j ].getName();
}
System.out.println(" le nombres des alerte est:"+nombreAlerte);
OntModel inf1 = ModelFactory.createOntologyModel();
for(int k=0;k< nombreAlerte;k++){
System.out.println(" \n"+list_alerte[k]);
}
Here it display my
Alert_1
Alert_2
Alert_3
How to get their properties?
UPDATE:
Thanks for your answer, it doesn't work yet. I tried now to do like you said
JenaOWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/base_connaissance.owl");
OntModel model = owlModel.getOntModel();
ArrayList<Resource> results = new ArrayList<Resource>();
ExtendedIterator individuals = model.listIndividuals();
while (individuals.hasNext()) {
Resource individual = (Resource) individuals.next();
results.add(individual);
}
for(int i = 0; i < results.size(); i++)
{
System.out.println("individual number " + i + " = " + results.get(i));//here it display my individual
Individual ind = model.getIndividual(results.get(i).toString());
Property hasTime = model.createProperty( "file:///D:/base_connaissance.owl#hasanalyser" );
RDFNode time = ind.getPropertyValue( hasTime );
System.out.println("property value of hasanalyser "+time);
At the end it displays all names of my individuals, and after each individual it display property value of hasanalyser NULL.
where is the problème please
IT WORK NOW , i can get now all properties of all individuals thanks lot , now what it doesnt work is HOW to add an individual and add properties to this individual and insert it into my "base_connaissance.owl" if you can help me i realy appreciate it here is the full code witch work perfectly .
static JenaOWLModel owlModel ;
public static void main(String[] args) {
OntModel model;
javax.swing.JDialog jDialog1 = new javax.swing.JDialog();
try{
String ns="file:///D:/base_connaissance.owl#";
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/base_connaissance.owl");// crée un modele owl a partir du ficher owl charger
model = owlModel.getOntModel();
JOptionPane.showMessageDialog(jDialog1,"chargement du fichier effectuer avec succé","Information",JOptionPane.INFORMATION_MESSAGE);
ArrayList<Resource> results = new ArrayList<Resource>();
ExtendedIterator individuals = model.listIndividuals();
while (individuals.hasNext()) {
Resource individual = (Resource) individuals.next();
results.add(individual);
}
System.out.println("\n");
for(int i = 0; i < results.size(); i++)
{
Individual ind = model.getIndividual(results.get(i).toString());
System.out.println(""+ind);
StmtIterator it = ind.listProperties();
while ( it.hasNext()) {
Statement s = (Statement) it.next();
if (s.getObject().isLiteral()) {
System.out.println(""+s.getLiteral().getLexicalForm().toString()+" type = "+s.getPredicate().getLocalName());
}
else System.out.println(""+s.getObject().toString().substring(53)+" type = "+s.getPredicate().getLocalName());
}
System.out.println("\n");
}
}
catch(Exception e){
JOptionPane.showMessageDialog(jDialog1,
"error",
"Information",
JOptionPane.INFORMATION_MESSAGE);
}
}
I'm not clear from your code how you are using Jena models. The OntModel called model does not appear to be used, nor does the InfModel called inf1. OWLIndividual is not a Jena class, but a Protégé one. The question asks about using the Jena API, however, so the rest of this answer assumes that you can get the Individuals that you are interested in, not the OWLIndividuals.
Jena's Individuals have a method getPropertyValue that returns the value of a property for the individual. You should be able to do something like this:
Individual alert1 = ...;
String hasTimeURI = "...";
Property hasTime = model.createProperty( hasTimeURI );
RDFNode time = alert1.getPropertyValue( hasTime );
The additional code you posted is printing null probably because the IRI for the property is incorrect. File-based IRIs are not very good identifiers; URIs are supposed to be universal identifiers, and something that includes a file path almost certainly isn't going to be universal. Without seeing your data, we cannot know what the proper IRI for the property should be. However, if you do something like this, you should be able to get enough information to determine what the property IRI should be.
Individual ind = model.getIndividual(results.get(i).toString());
// Check whether ind is null.
System.out.println( "ind: "+ind );
// Iterate over all the statements that have ind as subject.
StmtIterator it = ind.ListProperties();
while ( it.hasNext() ) {
System.out.println( it.next() );
}
Related
I prepare the program and I wrote this code with helping but the first 10 times it works then it gives me NULL values,
String url = "https://uzmanpara.milliyet.com.tr/doviz-kurlari/";
//Document doc = Jsoup.parse(url);
Document doc = null;
try {
doc = Jsoup.connect(url).timeout(6000).get();
} catch (IOException ex) {
Logger.getLogger(den3.class.getName()).log(Level.SEVERE, null, ex);
}
int i = 0;
String[] currencyStr = new String[11];
String[] buyStr = new String[11];
String[] sellStr = new String[11];
Elements elements = doc.select(".borsaMain > div:nth-child(2) > div:nth-child(1) > table.table-markets");
for (Element element : elements) {
Elements curreny = element.parent().select("td:nth-child(2)");
Elements buy = element.parent().select("td:nth-child(3)");
Elements sell = element.parent().select("td:nth-child(4)");
System.out.println(i);
currencyStr[i] = curreny.text();
buyStr[i] = buy.text();
sellStr[i] = sell.text();
System.out.println(String.format("%s [buy=%s, sell=%s]",
curreny.text(), buy.text(), sell.text()));
i++;
}
for(i = 0; i < 11; i++){
System.out.println("currency: " + currencyStr[i]);
System.out.println("buy: " + buyStr[i]);
System.out.println("sell: " + sellStr[i]);
}
here is the code, I guess it is a connection problem but I could not solve it I use Netbeans, Do I have to change the connection properties of Netbeans or should I have to add something more in the code
can you help me?
There's nothing wrong with the connection. Your query simply doesn't match the page structure.
Somewhere on your page, there's an element with class borsaMain, that has a direct child with class detL. And then somewhere in the descendants tree of detL, there is your table. You can write this as the following CSS element selector query:
.borsaMain > .detL table
There will be two tables in the result, but I suspect you are looking for the first one.
So basically, you want something like:
Element table = doc.selectFirst(".borsaMain > .detL table");
for (Element row : table.select("tr:has(td)")) {
// your existing loop code
}
I already generated an ont.owl file using Jena. Then first I need to take all the classes to the array list which are contain the ontology. secondly I will give another classes(terms) using my code and check whether these classes contain generated ontology or not. following is the code up to now.
m.read("http://localhost/myontofile/ont.owl");
ExtendedIterator<OntClass> classes = m.listClasses();
while (classes.hasNext()) {
OntClass takeclasses = (OntClass) classes.next();
String ontcls = takeclasses.getLocalName().toString();
ArrayList<String> listiter = new ArrayList<String>();
listiter.add(ontcls);
System.out.println("classes: " + listiter); ----------????
///////////////////////////////////////
ArrayList<String> tempTerms = new ArrayList<String>();
for(int i=0; i < terms.size(); i++) {
String aTerm = terms.get(i) ;
tempTerms.add(aTerm);
}
terms.add("Information");
terms.add("Video Information");
terms.add("Video Price Information");
terms.add("Video Maximum Price Information");
terms.add("Action Video Price Information");
for(int i=0; i < terms.size(); i++) {
if (listiter.equals(terms.get(i))==true) {
System.out.println("ok");
}
else {
System.out.println("no");
}
}
}
Result is always come to else ("no") part. "classes" give out put as only one class. What are the changes I need to do?
I am working on a JSF based Web Application where I read contents from a file(dumpfile) and then parse it using a logic and keep adding it to a list using an object and also set a string using the object. But I keep getting this error. I am confused where I am wrong. I am a beginner so can anyone be kind enough to help me?
List<DumpController> FinalDumpNotes;
public List<DumpController> initializeDumpNotes()
throws SocketException, IOException {
PostProcessedDump postProcessedDump = (PostProcessedDump) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("postProcessedDump");
List<DumpController> FinalNotes = new ArrayList<>();
if (postProcessedDump.getDumpNotes() == null) {
dumpNotes = new DumpNotes();
}
DumpListController dlcon = (DumpListController) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("dumpListController");
DumpInfo dumpinfo = dlcon.getSelectedDumpInfo();
String fileName = dumpinfo.getDate() + dumpinfo.getTime() + dumpinfo.getSeqNo() + dumpinfo.getType() + dumpinfo.getTape() + dumpinfo.getDescription() + ".txt";
if (checkFileExistsInWin(fileName)) {
postProcessedDump.setDumpnotescontent(getFileContentsFromWin(fileName));
String consolidateDumpnotes = getFileContentsFromWin(fileName);
String lines[];
String content = "";
lines = consolidateDumpnotes.split("\\r?\\n");
List<String> finallines = new ArrayList<>();
int k = 0;
for (int i = 0; i < lines.length; i++) {
if (!lines[i].equalsIgnoreCase("")) {
finallines.add(lines[i]);
k++;
}
}
for (int j = 0; j < finallines.size(); j++) {
if (finallines.get(j).startsWith("---------------------SAVED BY")) {
PostProcessedDump dump = new PostProcessedDump();
dump.setDumpMessage(content);
content = "";
FinalDumpNotes.add(dump);
} else {
content = content + finallines.get(j);
}
}
}
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("postProcessedDump", postProcessedDump);
return FinalDumpNotes;
}
I get the following error:
If you want to add instances of type PostProcessedDump to your List you should change it's type. Also, don't forget to initialize it. Something like,
List<PostProcessedDump> FinalDumpNotes = new ArrayList<>();
Also, Java naming convention is to start variable names with a lower case letter. FinalDumpNotes looks like a class, I would suggest something like
List<PostProcessedDump> processedList = new ArrayList<>();
Problems with your code:
List<DumpController> FinalDumpNotes;
You declare FinalDumpNotes to be a List of DumpController objects, but you never initialize it. In addition, your IDE is barfing on the following line of code:
FinalDumpNotes.add(dump);
because you are attempting to add a PostProcessedDump object to the List instead of a DumpController object.
For starters, you need to initialize your list like this:
List<DumpController> finalDumpNotes = new ArrayList<DumpController>();
Notice that I have made the variable name beginning with lower case, which is the convention (upper case is normally reserved for classes and interfaces).
I will leave it to you as a homework assignment to sort out the correct usage of this List.
I need to search for all documents in all workflow.
The document in workflow contains anything property, that indicates that the document is in some workflows?
Example:
results = search.luceneSearch("#cm\\:documentWorkflow:"+true);
I need create custom advanced search and search all documents in workflows.
Thanks in advance.
If it is a simple workflow there is an aspect called "{http://www.alfresco.org/model/application/1.0}simpleworkflow"
If you are an advanced workflow, have a parent type "packageContains" containing workflow in this node (parent) one aspect "{http://www.alfresco.org/model/bpm/1.0}workflowPackage"
You could perform a query something like:
search.luceneSearch results = ('ASPECT:"bpm:workflowPackage" ASPECT:"app:simpleWorkflow"');
Where node results contain this aspect, the children are documents.
For example:
var res = search
.luceneSearch('ASPECT:"bpm:workflowPackage" ASPECT:"app:simpleWorkflow"');
var par = null;
var c = null;
var s = "<html><body>total " + res.length + "<br>";
for (var i = 0; i < res.length; i++) {
if (res[i].hasAspect("bpm:workflowPackage")) {
par = res[i];
for each(c in par.children)
{
s += c.name + "<br>";
}
} else {
s += res[i].name + "<br>";
}
}
s += "</body></html>";
s;
Regards!
In my ontology, I have an individual that has this data property
hasName "somaName"^^string,
however, when i'm building a class expression and sending to the reasoner for get the instances, I'm getting an empty set with the following query,
OWLClassExpression x = schema.getFactory().getOWLDataHasValue(schema.getDataProperty("hasName"), schema.getFactory().getOWLLiteral("somaName"));
System.out.println(reasoner.getInstances(x, true));
the getDataProperty is just a small method:
public OWLDataProperty getDataProperty(String dataProperty){
return factory.getOWLDataProperty("#"+dataProperty,pm);
}
The following code snippet works, compare it to your code to see what's different. You should use a reasoner that support this type of construct (Hermit does).
//Initiate everything
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
String base = "http://www.example.org/";
OWLOntology ontology = manager.createOntology(IRI.create(base + "ontology.owl"));
OWLDataFactory factory = manager.getOWLDataFactory();
//Add the stuff to the ontology
OWLDataProperty hasName = factory.getOWLDataProperty(IRI.create(base + "hasName"));
OWLNamedIndividual john = factory.getOWLNamedIndividual(IRI.create(base + "john"));
OWLLiteral lit = factory.getOWLLiteral("John");
OWLDataPropertyAssertionAxiom ax =
factory.getOWLDataPropertyAssertionAxiom(hasName, john, lit);
AddAxiom addAx = new AddAxiom(ontology, ax);
manager.applyChange(addAx);
//Init of the reasoner
//I use Hermit because it supports the construct of interest
OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
reasoner.precomputeInferences();
//Prepare the expression for the query
OWLDataProperty p = factory.getOWLDataProperty(IRI.create(base + "hasName"));
OWLClassExpression ex =
factory.getOWLDataHasValue(p, factory.getOWLLiteral("John"));
//Print out the results, John is inside
Set<OWLNamedIndividual> result = reasoner.getInstances(ex, true).getFlattened();
for (OWLNamedIndividual owlNamedIndividual : result) {
System.out.println(owlNamedIndividual);
}