"Getting Started with UML" Referans Kartı

Öncelikle yazı seyrekliği için kusura bakmayın. İş, güç, yaşam, doktora, tez, makaleler. Zaman sıkıntısı var. Bir çok taslak bağlantı bekliyor paylaşılmak için, ama zaman yok. Yine de hızlıca bir paylaşımda bulunayım. DZone referans kartı olarak "Getting Started with UML" yayınlandı. İlgililere, başlamak isteyenlere, hatırlamak isteyenlere, referans kartı isteyenlere duyurulur.

Bugünlerde...

Uzun bir ara verdik yazmaya. Blogumuzun yazarları aynı zaman dilimlerinde çok yoğun ve farklı dönemler yaşıyor. Her birimiz bir yana dağılmış, bir yandan çoğunlukla gereksiz, yararsız işlerle uğraşıyor; diğer yandan hayatlarımızla ilgili seçimler ve yol ayrımları yaşıyoruz.

Bu aralar iş dışında yaptığım tek şey doğduğum şehir, Antakya hakkında araştırma yapmak. Bulduğum bilgileri toparlayınca paylaşacağım.

Oracle plsql de ref cursor örneği

Ref cursor kullanarak ihtiyacımı olan veri kümesi üzerinde çalışmaya bir örnek:
declare
type rec_musteri is record(
musteriNo number(20),
musteriAd varchar2(50));

rcMusteri omwb_emulation.globalpkg.RCT1;
erMusteri rec_musteri;

v_MusteriNo number(20);

begin

open rcMusteri for
select musterino, musteriAd
from tbl_musteri m
where m.tcknNo = TO_CHAR('01234567890');
exception
when others then
v_Hata := sqlerrm;

if rcMusteri%isopen then
loop
v_MusteriNo := '';
fetch rcMusteri
into erMusteri;
exit when rcMusteri%notfound;
v_MusteriNo := erMusteri.musteriNo;
v_MusteriAd := erMusteri.musteriAd;
end loop;
end if;
end;

SPARQL ve ARQ ile sorgu çalıştırma

Çalışmamızda bir Java uygulaması ile hazır bir ontoloji üzerinde sorgu çalıştırma yoluyla sonuca ulaşmayı hedefliyorduk. Çalıştıracağımız sorgu bir SPARQL sorgusu olacak ve Jena yardımı ile ontolojimiz içinden istediğimiz veriyi getirmeye çalışacaktı.

Bu amaçla öncelikle Jena SPARQL dökümanına bakmak yararlı olacaktır.

Jena SPARQL sorgularını işlemek üzere ARQ isimli bir kütüphane kullanıyor: ARQ dökümanı.


ARQ yardımı ile SPARQL sorgularına örnek olarak şu adreslere bakılabilir:
http://jena.sourceforge.net/ARQ/Tutorial/query1.html
http://www.ibm.com/developerworks/xml/library/j-sparql/

SPARQL ile sorgulama yapmak için örnek olarak aşağıdaki sorgu gibi bir sorgu hazırlayıp, yine aşağıda metodu çağırarak bu sorgunun sonucunu alabiliriz:

Q: which persons has same surname with "Ayder"

SPARQL:
PREFIX rdf: http://localhost/TestDocumentOntology.owl#
SELECT ?Result
WHERE { ?Person rdf:Surname ?Result .
FILTER regex(?Result, \"ayder\", \"i\" )}


import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.shared.ConfigException;
import com.hp.hpl.jena.shared.JenaException;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.Filter;


static OntModel ontModel = null;
static final String inputFileName = "MyOntology.owl";

public static OntModel loadOntology(){
try{

ontModel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );

InputStream in = FileManager.get().open( inputFileName );
if (in == null) {
throw new IllegalArgumentException( "File: " + inputFileName + " not found");
}

// read the RDF/XML file
ontModel.read(in, "");

}
catch (JenaException jx) {
if (jx.getCause() instanceof NoRouteToHostException
|| jx.getCause() instanceof UnknownHostException
|| jx.getCause() instanceof ConnectException
|| jx.getCause() instanceof IOException) {
System.out.println("Cannot access public internet - content negotiation test not executed");
} else
throw jx;
}

catch(Exception e){
System.out.println(e.getMessage());
}

return ontModel;
}

public static ArrayList executeQuery( ArrayList queryList ){
ArrayList resultList = new ArrayList();
String key = null;

System.out.println("------------------------------------");

// Execute the query and obtain results
QueryExecution qe = null;//QueryExecutionFactory.create(query[0], model);
ResultSet results = null;//qe.execSelect();

//use alternative queries
for(int i= 0; i < queryList.size() ; i++)
{
qe = QueryExecutionFactory.create(queryList.get(i).toString(), ontModel);
results = qe.execSelect();

System.out.println("**********************");
System.out.println("query : " + queryList.get(i) );
System.out.println("**********************");

if(results.hasNext())
{
resultList.add(ResultSetFormatter.asText(results));
// Output query results
//ResultSetFormatter.out(System.out, results);
for (int k=0;k
System.out.println(resultList.get(k));
break;
}else
{
System.out.println("NO RESULT for the query " + i);
}
}


// Important - free up resources used running the query
qe.close();

return resultList;
}

Ontology Mapping

Yaptığımız çalışmada bir Java uygulaması ile hazır bir ontoloji üzerinde sorgu çalıştırma yoluyla sonuca ulaşmayı hedefleliyorduk. Üzerinde çalışabileceğimiz hazır bir ontolojimiz yoksa, bu projede yaptığımız gibi, Protege uygulamasını kullanarak kendi ontolojimizi oluşturabiliriz.

Ontolojimizi oluşturduktan sonra aşağıda örneği görülen kod parçası yardımı ile, java içinden bu ontolojiye ulaşabilir, içerdiği class, property ve individual değerlerini alabiliriz.

import com.hp.hpl.jena.ontology.*;

import com.hp.hpl.jena.vocabulary.RDF;

import com.hp.hpl.jena.rdf.model.*;

import com.hp.hpl.jena.util.FileManager;

import com.hp.hpl.jena.shared.ConfigException;

import com.hp.hpl.jena.shared.JenaException;

import com.hp.hpl.jena.query.*;

import com.hp.hpl.jena.shared.PrefixMapping;

import com.hp.hpl.jena.util.iterator.ExtendedIterator;

import com.hp.hpl.jena.util.iterator.Filter;

public class OntoMapper {

static OntModel ontModel = null;

static final String inputFileName = "MyOntology.owl";

static ArrayList classList = null;

static ArrayList propertyList = null;

static ArrayList rootClassesList = null;

static ArrayList individualList = null;

public static OntModel loadOntology(){

try{

ontModel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );

InputStream in = FileManager.get().open( inputFileName );

if (in == null) {

throw new IllegalArgumentException( "File: " + inputFileName + " not found");

}

// read the RDF/XML file

ontModel.read(in, "");

}

catch (JenaException jx) {

if (jx.getCause() instanceof NoRouteToHostException

|| jx.getCause() instanceof UnknownHostException

|| jx.getCause() instanceof ConnectException

|| jx.getCause() instanceof IOException) {

System.out.println("Cannot access public internet - content negotiation test not executed");

} else

throw jx;

}

catch(Exception e){

System.out.println(e.getMessage());

}

if(classList == null)

classList = new ArrayList();

if(propertyList == null)

propertyList = new ArrayList();

if(rootClassesList == null)

rootClassesList = new ArrayList();

if(individualList == null)

individualList = new ArrayList();

OntClass superCls = null;

OntClass cls = null;

Property prty = null;

for (Iterator i = ontModel.listClasses(); i.hasNext(); ) {

cls = (OntClass) i.next();

System.out.println( "Class " + cls.getURI() );

classList.add(cls.getURI());

for (Iterator k = cls.listSubClasses( true ); k.hasNext(); )

{

rootClassesList.add(cls.getURI());

break;

}

Iterator iter = ontModel.listIndividuals();

while(iter.hasNext()){

Individual c = (Individual)iter.next();

System.out.println( "Individual " + c.getLocalName() );

individualList.add(c.getLocalName());

cls = (OntClass) c.getOntClass();

superCls = cls.getSuperClass();

Iterator iterTables = c.listProperties();

while (iterTables.hasNext()){

Statement stmt = (Statement)iterTables.next();

//Resource r = (Resource)stmt.getObject();

prty = (Property)stmt.getPredicate();

if (superCls != null)

{

System.out.println( "Property getLocalName::: " + prty.getLocalName());

propertyList.add(prty.getLocalName());

}

else

{

System.out.println( "Property getLocalName::: " + prty.getLocalName());

propertyList.add(prty.getLocalName());

}

}

}

}



İlgili Kaynaklar:
http://protege.stanford.edu/