void KoEventSemanticItemFactory::updateSemanticItems(QList<hKoRdfBasicSemanticItem> &semanticItems, const KoDocumentRdf *rdf, QSharedPointer<Soprano::Model> m) { const QString sparqlQuery = QLatin1String( " prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" " prefix cal: <http://www.w3.org/2002/12/cal/icaltzd#> \n" " select distinct ?graph ?ev ?uid ?dtstart ?dtend ?summary ?location ?geo ?long ?lat \n" " where { \n" " GRAPH ?graph { \n" " ?ev rdf:type cal:Vevent . \n" " ?ev cal:uid ?uid . \n" " ?ev cal:dtstart ?dtstart . \n" " ?ev cal:dtend ?dtend \n" " OPTIONAL { ?ev cal:summary ?summary } \n" " OPTIONAL { ?ev cal:location ?location } \n" " OPTIONAL { \n" " ?ev cal:geo ?geo . \n" " ?geo rdf:first ?lat . \n" " ?geo rdf:rest ?joiner . \n" " ?joiner rdf:first ?long \n" " } \n" " } \n" " } \n"); Soprano::QueryResultIterator it = m->executeQuery(sparqlQuery, Soprano::Query::QueryLanguageSparql); QList<hKoRdfBasicSemanticItem> oldSemanticItems = semanticItems; // uniqfilter is needed because soprano is not honouring // the DISTINCT sparql keyword QSet<QString> uniqfilter; while (it.next()) { const QString name = it.binding("uid").toString(); if (uniqfilter.contains(name)) { continue; } uniqfilter += name; hKoRdfBasicSemanticItem newSemanticItem(new KoRdfCalendarEvent(0, rdf, it)); const QString newSemanticItemLinkingSubject = newSemanticItem->linkingSubject().toString(); foreach (hKoRdfBasicSemanticItem semItem, oldSemanticItems) { if (newSemanticItemLinkingSubject == semItem->linkingSubject().toString()) { oldSemanticItems.removeAll(semItem); newSemanticItem = 0; break; } } if (newSemanticItem) { semanticItems << newSemanticItem; } } foreach (hKoRdfBasicSemanticItem semItem, oldSemanticItems) { semanticItems.removeAll(semItem); }
//TODO: next functions look like the ones from CAuSectionRdf. Maybe there is anyway to share code? void CAuActorSemanticItemFactory::updateSemanticItems( QList<hKoRdfBasicSemanticItem> &semanticItems, const KoDocumentRdf *rdf, QSharedPointer<Soprano::Model> m) { const QString sparqlQuery = CAuActorRdf::QUERY; Soprano::QueryResultIterator it = m->executeQuery( sparqlQuery, Soprano::Query::QueryLanguageSparql ); QList<hKoRdfBasicSemanticItem> oldSemanticItems = semanticItems; // uniqfilter is needed because soprano is not honouring // the DISTINCT sparql keyword QSet<QString> uniqfilter; while (it.next()) { QString magicid = it.binding("magicid").toString(); if (uniqfilter.contains(magicid)) { continue; } uniqfilter += magicid; hKoRdfBasicSemanticItem newSemanticItem(new CAuActorRdf(0, rdf, it)); const QString newItemLs = newSemanticItem->linkingSubject().toString(); foreach (hKoRdfBasicSemanticItem semItem, oldSemanticItems) { if (newItemLs == semItem->linkingSubject().toString()) { oldSemanticItems.removeAll(semItem); newSemanticItem = 0; break; } } if (newSemanticItem) { semanticItems << newSemanticItem; } } foreach (hKoRdfBasicSemanticItem semItem, oldSemanticItems) { semanticItems.removeAll(semItem); }