Smalyshev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/183410

Change subject: update fixes
......................................................................

update fixes

Change-Id: Ie1b3d9664daa76bc2dca0d81fe9f64ec0923a7a3
---
M src/main/groovy/org/wikidata/gremlin/DomainSpecificLanguage.groovy
M src/main/groovy/org/wikidata/gremlin/Loader.groovy
2 files changed, 36 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/gremlin 
refs/changes/10/183410/1

diff --git a/src/main/groovy/org/wikidata/gremlin/DomainSpecificLanguage.groovy 
b/src/main/groovy/org/wikidata/gremlin/DomainSpecificLanguage.groovy
index 95274b8..b5ad4cc 100644
--- a/src/main/groovy/org/wikidata/gremlin/DomainSpecificLanguage.groovy
+++ b/src/main/groovy/org/wikidata/gremlin/DomainSpecificLanguage.groovy
@@ -1,9 +1,6 @@
 package org.wikidata.gremlin
 
-import com.tinkerpop.gremlin.structure.Graph
-import com.tinkerpop.gremlin.structure.Vertex
-import com.tinkerpop.gremlin.structure.Edge
-import com.tinkerpop.gremlin.structure.Direction
+import com.tinkerpop.gremlin.structure.*
 
 import org.apache.commons.lang.RandomStringUtils
 import groovy.util.logging.Slf4j
@@ -11,10 +8,26 @@
 // Apache 2 Licensed
 @Slf4j
 class DomainSpecificLanguage {
+       
+       public static class DSLElement {
+               public static final get(final Element element, final String 
key) {
+                       final Property property = element.property(key)
+                       if (property.isPresent())
+                               return property.value();
+                       else
+                               return null
+               }
+
+               public static final set(final Element element, final String 
key, final Object value) {
+                       element.singleProperty(key, value)
+               }
+   }
+       
   void setup() {
        // Some syntax sugar for setting properties
-       Vertex.metaClass.getProperty = { this.property(it).value(); }
-       Vertex.metaClass.setProperty = { name, value -> 
this.singleProperty(name, value); }
+       // Conflicts with "sugar" plugin
+       Vertex.metaClass.mixin(DSLElement.class);
+       Edge.metaClass.mixin(DSLElement.class);
        
        return // for now
     log.info "Setting up domain specific language"
diff --git a/src/main/groovy/org/wikidata/gremlin/Loader.groovy 
b/src/main/groovy/org/wikidata/gremlin/Loader.groovy
index 04323e0..e17b02f 100644
--- a/src/main/groovy/org/wikidata/gremlin/Loader.groovy
+++ b/src/main/groovy/org/wikidata/gremlin/Loader.groovy
@@ -376,19 +376,20 @@
                        return
                }
                for(cl in v.outE('claim')) {
-                       if(!(cl.contentHash in claimsById)) {
+                       def clHash = cl.value('contentHash')
+                       if(!(clHash in claimsById)) {
                                // This one is not there anymore, remove it
-                               def prop = cl.property('property').value()
+                               def prop = cl.value('property')
                                def targetId = null
-                               log.debug "Dropping old claim ${cl.wikibaseId}"
-                               if(isLinkType(cl.property('datatype').value())) 
{
+                               log.info "Dropping old claim ${cl.wikibaseId} 
on $prop"
+                               if(isLinkType(cl.value('datatype'))) {
                                        // Try to find target id for this link
-                                       def e = v.outE(prop).has('contentHash', 
cl.contentHash).next()
-                                       targetId = 
e.property(getValueName(prop)).value()
+                                       def e = v.outE(prop).has('contentHash', 
clHash).next()
+                                       targetId = e.value(getValueName(prop))
                                }
                                // Drop related claims
-                               v.outE('claim').has('contentHash', 
cl.contentHash).remove()
-                               v.outE(prop).has('contentHash', 
cl.contentHash).remove()
+                               v.outE('claim').has('contentHash', 
clHash).remove()
+                               v.outE(prop).has('contentHash', clHash).remove()
                                // update also the links
                                if(targetId && targetId[0] == 'Q'
                                        && !v.out(prop).has('wikibaseId', 
targetId).hasNext()) {
@@ -396,15 +397,19 @@
                                        // if this link targeted v(target) and 
there are no links to it anymore
                                        // drop it from links
                                        for(vp in v.properties(lname)) {
-                                               if(vp.value() == 
target.wikibaseId) {
+                                               if(vp.value() == targetId) {
                                                        vp.remove();
                                                        break;
                                                }
                                        }
-                                       v.singleProperty(getLinkName(prop)+"_", 
v[lname].join(' '))
+                                       if(v[lname]) {
+                                               
v.singleProperty(getLinkName(prop)+"_", v[lname].join(' '))
+                                       } else {
+                                               
v.property(getLinkName(prop)+"_").remove()
+                                       }
                                }
                        } else {
-                               claimsById[cl.contentHash].exists = true
+                               claimsById[clHash].exists = true
                        }
                }
        }
@@ -737,7 +742,7 @@
          def rank = s.addProperty(mgmt, 'rank', Boolean.class)
          def hash = s.addProperty(mgmt, "contentHash", String.class)
          def etype = s.addProperty(mgmt, 'edgeType', String.class)
-         def datatype = addProperty(mgmt, 'datatype', String.class)
+         def datatype = s.addProperty(mgmt, 'datatype', String.class)
          def label = s.addEdgeLabel(mgmt, name, rank, wikibaseId, hash, etype, 
datatype)
          
 

-- 
To view, visit https://gerrit.wikimedia.org/r/183410
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1b3d9664daa76bc2dca0d81fe9f64ec0923a7a3
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/gremlin
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to