Source Code Cross Referenced for ThesaurusManagerSesame.java in  » GIS » geonetwork » org » fao » geonet » kernel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » geonetwork » org.fao.geonet.kernel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //===	Copyright (C) 2001-2005 Food and Agriculture Organization of the
002:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
003:        //===	and United Nations Environment Programme (UNEP)
004:        //===
005:        //===	This program is free software; you can redistribute it and/or modify
006:        //===	it under the terms of the GNU General Public License as published by
007:        //===	the Free Software Foundation; either version 2 of the License, or (at
008:        //===	your option) any later version.
009:        //===
010:        //===	This program is distributed in the hope that it will be useful, but
011:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
012:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:        //===	General Public License for more details.
014:        //===
015:        //===	You should have received a copy of the GNU General Public License
016:        //===	along with this program; if not, write to the Free Software
017:        //===	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:        //===
019:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
020:        //===	Rome - Italy. email: GeoNetwork@fao.org
021:        //==============================================================================
022:
023:        package org.fao.geonet.kernel;
024:
025:        import java.io.File;
026:        import java.io.FilenameFilter;
027:        import java.io.IOException;
028:        import java.util.Date;
029:        import java.util.Hashtable;
030:
031:        import org.fao.geonet.constants.Geonet;
032:        import org.jdom.Element;
033:        import org.openrdf.model.BNode;
034:        import org.openrdf.model.Graph;
035:        import org.openrdf.model.GraphException;
036:        import org.openrdf.model.Literal;
037:        import org.openrdf.model.Statement;
038:        import org.openrdf.model.URI;
039:        import org.openrdf.model.Value;
040:        import org.openrdf.model.ValueFactory;
041:        import org.openrdf.sesame.Sesame;
042:        import org.openrdf.sesame.config.AccessDeniedException;
043:        import org.openrdf.sesame.config.ConfigurationException;
044:        import org.openrdf.sesame.config.RepositoryConfig;
045:        import org.openrdf.sesame.config.SailConfig;
046:        import org.openrdf.sesame.constants.QueryLanguage;
047:        import org.openrdf.sesame.constants.RDFFormat;
048:        import org.openrdf.sesame.query.MalformedQueryException;
049:        import org.openrdf.sesame.query.QueryEvaluationException;
050:        import org.openrdf.sesame.query.QueryResultsTable;
051:        import org.openrdf.sesame.repository.local.LocalRepository;
052:        import org.openrdf.sesame.repository.local.LocalService;
053:        import org.openrdf.sesame.sail.StatementIterator;
054:
055:        //=============================================================================
056:
057:        public class ThesaurusManagerSesame {
058:
059:            private Hashtable<String, LocalRepository> repositoryTable = null;
060:
061:            private Hashtable<String, Thesaurus> thesauriTable = null;
062:
063:            private LocalService service = null;
064:
065:            private String thesauriDirectory = null;
066:
067:            /**
068:             * 
069:             * @param appPath
070:             * @param thesauriRepository
071:             * @throws Exception
072:             */
073:            public ThesaurusManagerSesame(String appPath,
074:                    String thesauriRepository) throws Exception {
075:                // Get Sesame interface
076:                service = Sesame.getService();
077:
078:                File thesauriDir = new File(thesauriRepository);
079:
080:                if (!thesauriDir.isAbsolute())
081:                    thesauriDir = new File(appPath + thesauriDir);
082:
083:                thesauriDirectory = thesauriDir.getAbsolutePath();
084:
085:                initThesauriTable(thesauriDir);
086:            }
087:
088:            /**
089:             * @param fname
090:             * @param type
091:             * @param dname
092:             * @return
093:             */
094:            public String buildThesaurusFilePath(String fname, String type,
095:                    String dname) {
096:                return thesauriDirectory + File.separator + type
097:                        + File.separator + Geonet.CodeList.THESAURUS
098:                        + File.separator + dname + File.separator + fname;
099:            }
100:
101:            /**
102:             * 
103:             * @param thesauriDirectory
104:             */
105:            private void initThesauriTable(File thesauriDirectory) {
106:
107:                repositoryTable = new Hashtable<String, LocalRepository>();
108:                thesauriTable = new Hashtable<String, Thesaurus>();
109:
110:                if (thesauriDirectory.isDirectory()) {
111:                    // init of external repositories
112:                    File externalThesauriDirectory = new File(
113:                            thesauriDirectory, Geonet.CodeList.EXTERNAL
114:                                    + File.separator
115:                                    + Geonet.CodeList.THESAURUS);
116:                    if (externalThesauriDirectory.isDirectory()) {
117:                        File[] rdfDataDirectory = externalThesauriDirectory
118:                                .listFiles();
119:                        for (int i = 0; i < rdfDataDirectory.length; i++) {
120:                            if (rdfDataDirectory[i].isDirectory()) {
121:                                loadRepositories(rdfDataDirectory[i],
122:                                        Geonet.CodeList.EXTERNAL);
123:                            }
124:                        }
125:                    }
126:
127:                    // init of local repositoris
128:                    File localThesauriDirectory = new File(thesauriDirectory,
129:                            Geonet.CodeList.LOCAL + File.separator
130:                                    + Geonet.CodeList.THESAURUS);
131:                    if (localThesauriDirectory.isDirectory()) {
132:                        File[] rdfDataDirectory = localThesauriDirectory
133:                                .listFiles();
134:                        for (int i = 0; i < rdfDataDirectory.length; i++) {
135:                            if (rdfDataDirectory[i].isDirectory()) {
136:                                loadRepositories(rdfDataDirectory[i],
137:                                        Geonet.CodeList.LOCAL);
138:                            }
139:                        }
140:                    }
141:                }
142:            }
143:
144:            /**
145:             * 
146:             * @param thesauriDirectory
147:             */
148:            private void loadRepositories(File thesauriDirectory, String root) {
149:                FilenameFilter filter = new FilenameFilter() {
150:                    public boolean accept(File dir, String name) {
151:                        return name.endsWith(".rdf");
152:                    }
153:                };
154:
155:                String[] rdfDataFile = thesauriDirectory.list(filter);
156:
157:                for (int i = 0; i < rdfDataFile.length; i++) {
158:
159:                    Thesaurus gst = new Thesaurus(rdfDataFile[i], root,
160:                            thesauriDirectory.getName(), new File(
161:                                    thesauriDirectory, rdfDataFile[i]));
162:                    try {
163:                        addThesaurus(gst);
164:                    } catch (Exception e) {
165:                        e.printStackTrace();
166:                        // continue loading
167:                    }
168:                }
169:            }
170:
171:            /**
172:             * 
173:             * @param gst
174:             */
175:            public void addThesaurus(Thesaurus gst) throws Exception {
176:
177:                String thesaurusName = gst.getKey();
178:                if (existsThesaurus(thesaurusName)) {
179:                    throw new Exception("A thesaurus exists with code "
180:                            + thesaurusName);
181:                }
182:
183:                addConfiguredThesaurus(gst);
184:            }
185:
186:            /**
187:             * TODO TEST
188:             * 
189:             * @param gst
190:             */
191:            private void addConfiguredThesaurus(Thesaurus gst) throws Exception {
192:
193:                String thesaurusName = gst.getKey();
194:                if (existsThesaurus(thesaurusName)) {
195:                    throw new Exception("A thesaurus exists with code "
196:                            + thesaurusName);
197:                }
198:
199:                // boolean inferencing = true;
200:                // boolean inferencing = false;
201:
202:                LocalRepository thesaurusRepository;
203:                try {
204:                    RepositoryConfig repConfig = new RepositoryConfig(gst
205:                            .getKey());
206:
207:                    SailConfig syncSail = new SailConfig(
208:                            "org.openrdf.sesame.sailimpl.sync.SyncRdfSchemaRepository");
209:                    SailConfig memSail = new org.openrdf.sesame.sailimpl.memory.RdfSchemaRepositoryConfig(
210:                            gst.getFile().getAbsolutePath(), RDFFormat.RDFXML);
211:                    repConfig.addSail(syncSail);
212:                    repConfig.addSail(memSail);
213:                    repConfig.setWorldReadable(true);
214:                    repConfig.setWorldWriteable(true);
215:
216:                    thesaurusRepository = service.createRepository(repConfig);
217:
218:                    // create thesaurus repository
219:                    // thesaurusRepository = service.createRepository(thesaurusName,
220:                    // inferencing);
221:
222:                    // populate thesaurus repository
223:                    // String baseURI = "http://www.w3.org/2004/02/skos/core#";
224:                    // boolean verifyData = false;
225:                    // AdminListener myListener = new StdOutAdminListener();
226:                    // thesaurusRepository.addData(gst.getFile(), baseURI,
227:                    // RDFFormat.RDFXML, verifyData,
228:                    // myListener);
229:
230:                    // put thesaurus in hashtable
231:                    repositoryTable.put(thesaurusName, thesaurusRepository);
232:                    thesauriTable.put(thesaurusName, gst);
233:
234:                } catch (ConfigurationException e) {
235:                    e.printStackTrace();
236:                    throw e;
237:                }
238:                // catch (IOException e) {
239:                // e.printStackTrace();
240:                // throw e;
241:                // } catch (AccessDeniedException e) {
242:                // e.printStackTrace();
243:                // throw e;
244:                // }
245:            }
246:
247:            /**
248:             * TODO What happen if SESAME repository destoyed ?
249:             * 
250:             * @param name
251:             */
252:            public void remove(String name) {
253:                thesauriTable.remove(name);
254:                repositoryTable.remove(name);
255:            }
256:
257:            // =============================================================================
258:            // PUBLIC SERVICES
259:
260:            public String getThesauriDirectory() {
261:                return thesauriDirectory;
262:            }
263:
264:            public Hashtable<String, LocalRepository> getRepositoryTable() {
265:                return repositoryTable;
266:            }
267:
268:            public Hashtable<String, Thesaurus> getThesauriTable() {
269:                return thesauriTable;
270:            }
271:
272:            public LocalRepository getRepositoryByName(String thesaurusName) {
273:                return repositoryTable.get(thesaurusName);
274:            }
275:
276:            public Thesaurus getThesaurusByName(String thesaurusName) {
277:                return thesauriTable.get(thesaurusName);
278:            }
279:
280:            /**
281:             * 
282:             * @param query
283:             * @param thesaurusRepository
284:             * @return
285:             * @throws IOException
286:             * @throws MalformedQueryException
287:             * @throws QueryEvaluationException
288:             * @throws AccessDeniedException
289:             */
290:            public QueryResultsTable performRequest(String query,
291:                    LocalRepository thesaurusRepository) throws IOException,
292:                    MalformedQueryException, QueryEvaluationException,
293:                    AccessDeniedException {
294:
295:                System.out.println("Requete : " + query);
296:
297:                QueryResultsTable resultsTable = thesaurusRepository
298:                        .performTableQuery(QueryLanguage.SERQL, query);
299:
300:                printResultsTable(resultsTable);
301:
302:                return resultsTable;
303:            }
304:
305:            /**
306:             * 
307:             * @param thesaurusRepository
308:             * @return
309:             * @throws IOException
310:             * @throws MalformedQueryException
311:             * @throws QueryEvaluationException
312:             * @throws AccessDeniedException
313:             */
314:            public Element getAllPrefLabel(String thesaurusRepository)
315:                    throws IOException, MalformedQueryException,
316:                    QueryEvaluationException, AccessDeniedException {
317:
318:                String query = "SELECT prefLab, note "
319:                        + " from {} rdf:type {skos:Concept}; "
320:                        + " skos:prefLabel {prefLab} [skos:scopeNote {note}] "
321:                        + " where lang(prefLab) like \"fr\""
322:                        + " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>";
323:
324:                QueryResultsTable resultsTable = performRequest(query,
325:                        repositoryTable.get(thesaurusRepository));
326:
327:                printResultsTable(resultsTable);
328:
329:                Element elDescKeys = resultsTableToXmlKeywords(resultsTable,
330:                        thesaurusRepository);
331:                Element elThesaName = new Element("thesaName");
332:                Element elResTitle = new Element("resTitle");
333:                elResTitle.addContent(thesaurusRepository);
334:                elThesaName.addContent(elResTitle);
335:                elDescKeys.addContent(elThesaName);
336:
337:                return elDescKeys;
338:            }
339:
340:            /**
341:             * 
342:             * @param thesaurusRepository
343:             * @param word
344:             * @return
345:             * @throws IOException
346:             * @throws MalformedQueryException
347:             * @throws QueryEvaluationException
348:             * @throws AccessDeniedException
349:             */
350:            public Element getPrefLabelBeginingWith(String thesaurusRepository,
351:                    String word) throws IOException, MalformedQueryException,
352:                    QueryEvaluationException, AccessDeniedException {
353:
354:                String query = "SELECT prefLab, note "
355:                        + " from {} rdf:type {skos:Concept}; "
356:                        + " skos:prefLabel {prefLab} [skos:scopeNote {note}] "
357:                        + " where lang(prefLab) like \"fr\" and prefLab like \""
358:                        + word
359:                        + "*\" "
360:                        + " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>";
361:
362:                QueryResultsTable resultsTable = performRequest(query,
363:                        repositoryTable.get(thesaurusRepository));
364:
365:                printResultsTable(resultsTable);
366:
367:                Element elDescKeys = resultsTableToXmlKeywords(resultsTable,
368:                        thesaurusRepository);
369:                Element elThesaName = new Element("thesaName");
370:                Element elResTitle = new Element("resTitle");
371:                elResTitle.addContent(thesaurusRepository);
372:                elThesaName.addContent(elResTitle);
373:                elDescKeys.addContent(elThesaName);
374:
375:                return elDescKeys;
376:            }
377:
378:            /**
379:             * 
380:             * @param thesaurusRepository
381:             * @param word
382:             * @return
383:             * @throws IOException
384:             * @throws MalformedQueryException
385:             * @throws QueryEvaluationException
386:             * @throws AccessDeniedException
387:             */
388:            public Element getPrefLabelIncluding(String thesaurusRepository,
389:                    String word) throws IOException, MalformedQueryException,
390:                    QueryEvaluationException, AccessDeniedException {
391:
392:                String query = "SELECT prefLab, note "
393:                        + " from {} rdf:type {skos:Concept}; "
394:                        + " skos:prefLabel {prefLab} [skos:scopeNote {note}] "
395:                        + " where lang(prefLab) like \"fr\" and prefLab like \"*"
396:                        + word
397:                        + "*\" "
398:                        + " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>";
399:
400:                QueryResultsTable resultsTable = performRequest(query,
401:                        repositoryTable.get(thesaurusRepository));
402:
403:                printResultsTable(resultsTable);
404:
405:                Element elDescKeys = resultsTableToXmlKeywords(resultsTable,
406:                        thesaurusRepository);
407:                Element elThesaName = new Element("thesaName");
408:                Element elResTitle = new Element("resTitle");
409:                elResTitle.addContent(thesaurusRepository);
410:                elThesaName.addContent(elResTitle);
411:                elDescKeys.addContent(elThesaName);
412:
413:                return elDescKeys;
414:            }
415:
416:            /**
417:             * 
418:             * @param thesaurusRepository
419:             * @param word
420:             * @return
421:             * @throws IOException
422:             * @throws MalformedQueryException
423:             * @throws QueryEvaluationException
424:             * @throws AccessDeniedException
425:             */
426:            public Element getPrefLabel(String thesaurusRepository, String word)
427:                    throws IOException, MalformedQueryException,
428:                    QueryEvaluationException, AccessDeniedException {
429:
430:                String query = "SELECT prefLab, note "
431:                        + " from {} rdf:type {skos:Concept}; "
432:                        + " skos:prefLabel {prefLab} [skos:scopeNote {note}] "
433:                        + " where lang(prefLab) like \"fr\" and prefLab like \""
434:                        + word
435:                        + "\" "
436:                        + " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>";
437:
438:                QueryResultsTable resultsTable = performRequest(query,
439:                        repositoryTable.get(thesaurusRepository));
440:
441:                printResultsTable(resultsTable);
442:
443:                Element elDescKeys = resultsTableToXmlKeywords(resultsTable,
444:                        thesaurusRepository);
445:                Element elThesaName = new Element("thesaName");
446:                Element elResTitle = new Element("resTitle");
447:                elResTitle.addContent(thesaurusRepository);
448:                elThesaName.addContent(elResTitle);
449:                elDescKeys.addContent(elThesaName);
450:
451:                return elDescKeys;
452:            }
453:
454:            /**
455:             * 
456:             * @param resultsTable
457:             */
458:            private void printResultsTable(QueryResultsTable resultsTable) {
459:                int rowCount = resultsTable.getRowCount();
460:                int columnCount = resultsTable.getColumnCount();
461:
462:                for (int row = 0; row < rowCount; row++) {
463:                    for (int column = 0; column < columnCount; column++) {
464:                        Value value = resultsTable.getValue(row, column);
465:
466:                        if (value != null) {
467:                            System.out.print(value.toString());
468:                        } else {
469:                            System.out.print("null");
470:                        }
471:
472:                        System.out.print("\t");
473:                    }
474:
475:                    System.out.println();
476:                }
477:            }
478:
479:            /**
480:             * 
481:             * @param resultsTable
482:             * @param thesaurusRepository
483:             * @return
484:             */
485:            private Element resultsTableToXmlKeywords(
486:                    QueryResultsTable resultsTable, String thesaurusRepository) {
487:
488:                Element elDescKeys = new Element("descKeys");
489:
490:                int rowCount = resultsTable.getRowCount();
491:
492:                for (int row = 0; row < rowCount; row++) {
493:                    Element elKeyword = new Element("keyword");
494:
495:                    Value value = resultsTable.getValue(row, 0);
496:                    String sValue = "";
497:                    if (value != null) {
498:                        sValue = value.toString();
499:                    }
500:                    Element elValue = new Element("value");
501:                    elValue.addContent(sValue);
502:
503:                    Value definition = resultsTable.getValue(row, 1);
504:                    String sDefinition = "";
505:                    if (definition != null) {
506:                        sDefinition = definition.toString();
507:                    }
508:                    Element elDefiniton = new Element("definiton");
509:                    elDefiniton.addContent(sDefinition);
510:
511:                    elKeyword.addContent(elValue);
512:                    elKeyword.addContent(elDefiniton);
513:                    elDescKeys.addContent(elKeyword);
514:                }
515:
516:                Element elNbResultsTot = new Element("nbresultstot");
517:                elNbResultsTot.addContent(Integer.toString(rowCount));
518:                elDescKeys.addContent(elNbResultsTot);
519:
520:                return elDescKeys;
521:            }
522:
523:            /**
524:             * @param name
525:             * @return
526:             */
527:            public boolean existsThesaurus(String name) {
528:                return (thesauriTable.get(name) != null);
529:            }
530:
531:            /**
532:             * @param name
533:             * @return
534:             */
535:            public boolean updateThesaurus(String thesaurusName,
536:                    Hashtable htChanges) {
537:                return false;
538:            }
539:
540:            /**
541:             * @param args
542:             * @throws GraphException
543:             * @throws Exception
544:             */
545:            public boolean addElement(String thesaurusName, String prefLab,
546:                    String altLab, String note) throws GraphException {
547:                LocalRepository lr = repositoryTable.get(thesaurusName);
548:
549:                // Graph myGraph = myLocalRepository.getGraph();
550:                Graph myGraph = new org.openrdf.model.impl.GraphImpl();
551:
552:                ValueFactory myFactory = myGraph.getValueFactory();
553:
554:                // Define namespace
555:                String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
556:                String namespaceGml = "http://www.opengis.net/gml#";
557:                String namespace = "http://geosource.org/keyword#";
558:
559:                // Subject
560:                URI mySubject = myFactory.createURI(namespace, Long
561:                        .toString((new Date()).getTime()));
562:
563:                URI skosClass = myFactory.createURI(namespaceSkos, "Concept");
564:                URI rdfType = myFactory
565:                        .createURI(org.openrdf.vocabulary.RDF.TYPE);
566:                URI predicatePrefLabel = myFactory.createURI(namespaceSkos,
567:                        "prefLabel");
568:                URI predicateScopeNote = myFactory.createURI(namespaceSkos,
569:                        "scopeNote");
570:
571:                URI predicateBoundedBy = myFactory.createURI(namespaceGml,
572:                        "BoundedBy");
573:                URI predicateEnvelope = myFactory.createURI(namespaceGml,
574:                        "Envelope");
575:                URI predicateSrsName = myFactory.createURI(namespaceGml,
576:                        "srsName");
577:                URI srsNameURI = myFactory
578:                        .createURI("http://www.opengis.net/gml/srs/epsg.xml#epsg:4326");
579:                BNode gmlNode = myFactory.createBNode();
580:                URI predicateLowerCorner = myFactory.createURI(namespaceGml,
581:                        "lowerCorner");
582:                URI predicateUpperCorner = myFactory.createURI(namespaceGml,
583:                        "upperCorner");
584:
585:                // creation des objets
586:                Literal myObject1 = myFactory.createLiteral(prefLab, "fr");
587:                Literal myObject2 = myFactory.createLiteral(note);
588:
589:                Literal lowerCorner = myFactory.createLiteral("12.23 12.56");
590:                Literal upperCorner = myFactory.createLiteral("15.12 16.0");
591:
592:                //preparation du graph
593:                mySubject.addProperty(rdfType, skosClass);
594:                myGraph.add(mySubject, predicatePrefLabel, myObject1);
595:                myGraph.add(mySubject, predicateScopeNote, myObject2);
596:                myGraph.add(mySubject, predicateBoundedBy, gmlNode);
597:                //graph gml		
598:                gmlNode.addProperty(rdfType, predicateEnvelope);
599:                myGraph.add(gmlNode, predicateLowerCorner, lowerCorner);
600:                myGraph.add(gmlNode, predicateUpperCorner, upperCorner);
601:                myGraph.add(gmlNode, predicateSrsName, srsNameURI);
602:
603:                try {
604:                    lr.addGraph(myGraph);
605:                } catch (IOException e) {
606:                    // TODO Auto-generated catch block
607:                    e.printStackTrace();
608:                    return false;
609:                } catch (AccessDeniedException e) {
610:                    // TODO Auto-generated catch block
611:                    e.printStackTrace();
612:                    return false;
613:                }
614:
615:                return true;
616:            }
617:
618:            /**
619:             * TODO ETAPE 3
620:             * 
621:             * @param args
622:             * @throws QueryEvaluationException
623:             * @throws MalformedQueryException
624:             * @throws AccessDeniedException
625:             * @throws Exception
626:             */
627:            public boolean updateElement(String thesaurusName, String prefLab,
628:                    String altLab, String note) throws MalformedQueryException,
629:                    QueryEvaluationException, AccessDeniedException {
630:                LocalRepository lr = repositoryTable.get(thesaurusName);
631:                Graph myGraph = lr.getGraph();
632:
633:                ValueFactory myFactory = myGraph.getValueFactory();
634:                String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
635:
636:                URI subject = myFactory
637:                        .createURI("http://geosource.org/keyword#1165509663312");
638:
639:                URI predicatePrefLabel = myFactory.createURI(namespaceSkos,
640:                        "prefLabel");
641:                Literal myObject1 = myFactory.createLiteral(prefLab, "fr");
642:
643:                URI predicateScopeNote = myFactory.createURI(namespaceSkos,
644:                        "scopeNote");
645:                Literal myObject2 = myFactory.createLiteral(note, "fr");
646:
647:                StatementIterator iter = myGraph.getStatements(subject,
648:                        predicateScopeNote, null);
649:                while (iter.hasNext()) {
650:                    Statement st = (Statement) iter.next();
651:                    if (st.getObject() instanceof  Literal) {
652:                        Literal litt = (Literal) st.getObject();
653:                        System.out.println(st.getSubject().toString() + " : "
654:                                + st.getPredicate().getLocalName() + " : "
655:                                + st.getObject().toString() + " : "
656:                        /*+ litt.getLanguage()*/);
657:                        if (litt.getLanguage() != null
658:                                && litt.getLanguage().equals("fr")) {
659:                            System.out.println("a supprimer");
660:                            //myGraph.remove(st);
661:                            //break;
662:                        }
663:                    }
664:                }
665:                return false;
666:            }
667:
668:            /**
669:             * TODO TEST ETAPE 3
670:             * 
671:             * @param args
672:             * @throws GraphException
673:             * @throws Exception
674:             */
675:            public boolean deleteElement(String thesaurusName, String prefLab,
676:                    String altLab, String note) throws GraphException {
677:                LocalRepository lr = repositoryTable.get(thesaurusName);
678:
679:                Graph myGraph = new org.openrdf.model.impl.GraphImpl();
680:
681:                ValueFactory myFactory = myGraph.getValueFactory();
682:                String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
683:                String namespace = "http://geosource.org/keyword#";
684:
685:                URI mySubject = myFactory.createURI(namespace, Long
686:                        .toString((new Date()).getTime()));
687:
688:                URI skosClass = myFactory.createURI(namespaceSkos, "Concept");
689:                URI rdfType = myFactory
690:                        .createURI(org.openrdf.vocabulary.RDF.TYPE);
691:                mySubject.addProperty(rdfType, skosClass);
692:
693:                URI myPredicate1 = myFactory.createURI(namespaceSkos,
694:                        "prefLabel");
695:                Literal myObject1 = myFactory.createLiteral(prefLab, "fr");
696:                myGraph.add(mySubject, myPredicate1, myObject1);
697:
698:                URI myPredicate2 = myFactory.createURI(namespaceSkos,
699:                        "scopeNote");
700:                Literal myObject2 = myFactory.createLiteral(note);
701:                myGraph.add(mySubject, myPredicate2, myObject2);
702:
703:                // Graph myGraph = new org.openrdf.model.impl.GraphImpl();
704:                //
705:                // ValueFactory myFactory = myGraph.getValueFactory();
706:                // String namespace = "http://www.w3.org/2004/02/skos/core#";
707:                //
708:                // org.openrdf.model.URI mySubject = myFactory.createURI(namespace,
709:                // "Concept");
710:                //		
711:                // org.openrdf.model.URI myPredicate1 = myFactory.createURI(namespace,
712:                // "prefLabel");
713:                // Literal myObject1 = myFactory.createLiteral(prefLab);
714:                // myGraph.add(mySubject, myPredicate1, myObject1);
715:                //		
716:                // org.openrdf.model.URI myPredicate2 = myFactory.createURI(namespace,
717:                // "scopeNote");
718:                // Literal myObject2 = myFactory.createLiteral(note);
719:                // myGraph.add(mySubject, myPredicate2, myObject2);
720:
721:                try {
722:                    lr.removeGraph(myGraph);
723:                } catch (IOException e) {
724:                    // TODO Auto-generated catch block
725:                    e.printStackTrace();
726:                    return false;
727:                } catch (AccessDeniedException e) {
728:                    // TODO Auto-generated catch block
729:                    e.printStackTrace();
730:                    return false;
731:                }
732:
733:                return true;
734:            }
735:
736:            // =============================================================================
737:
738:            public static void main(String[] args) throws Exception {
739:                ThesaurusManagerSesame tm = new ThesaurusManagerSesame("",
740:                        "E:\\workspace3.2\\TestSesame\\res\\codelist\\");
741:                //		 tm.addElement("local.place.regions", "monPays", "le pays de toto", "le pays de toto");
742:                // tm.deleteElement("local.place.regions", "monPays", "le pays", "voila
743:                // un pays");
744:                //		tm.updateElement("local.place.regions", "Zimbabwe", "le pays",
745:                //				"voila un pays");
746:                // tm.getAllPrefLabel("local.place.regions");
747:                File rdf = new File(
748:                        "E:\\workspace3.2\\TestSesame\\res\\codelist\\local\\thesauri\\place\\toto.rdf");
749:                Thesaurus thesaurus = new Thesaurus("toto.rdf", "local",
750:                        "place", rdf);
751:                tm.addThesaurus(thesaurus);
752:
753:                tm.getAllPrefLabel("local.place.toto");
754:
755:                tm.addElement("local.place.toto", "monPays", "le pays de toto",
756:                        "le pays de toto");
757:                tm.getAllPrefLabel("local.place.toto");
758:                System.out.println("fin!!");
759:            }
760:
761:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.