openbel-api 0.6.2-java → 1.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gemspec +11 -14
 - data/CHANGELOG.md +18 -12
 - data/README.md +25 -36
 - data/VERSION +1 -1
 - data/app/openbel/api/app.rb +13 -12
 - data/app/openbel/api/config.rb +53 -11
 - data/app/openbel/api/helpers/{evidence.rb → nanopub.rb} +13 -14
 - data/app/openbel/api/middleware/auth.rb +22 -29
 - data/app/openbel/api/resources/annotation.rb +7 -7
 - data/app/openbel/api/resources/function.rb +12 -35
 - data/app/openbel/api/resources/namespace.rb +13 -13
 - data/app/openbel/api/resources/{evidence.rb → nanopub.rb} +23 -23
 - data/app/openbel/api/resources/{evidence_transform.rb → nanopub_transform.rb} +8 -8
 - data/app/openbel/api/resources/relationship.rb +74 -0
 - data/app/openbel/api/routes/annotations.rb +1 -1
 - data/app/openbel/api/routes/base.rb +11 -7
 - data/app/openbel/api/routes/datasets.rb +74 -84
 - data/app/openbel/api/routes/expressions.rb +86 -396
 - data/app/openbel/api/routes/language.rb +118 -0
 - data/app/openbel/api/routes/namespaces.rb +2 -2
 - data/app/openbel/api/routes/{evidence.rb → nanopubs.rb} +68 -69
 - data/app/openbel/api/routes/root.rb +2 -2
 - data/app/openbel/api/routes/version.rb +37 -23
 - data/app/openbel/api/schemas/annotation_resource.schema.json +1 -1
 - data/app/openbel/api/schemas/{evidence.schema.json → nanopub.schema.json} +10 -10
 - data/app/openbel/api/schemas/{evidence_collection.schema.json → nanopub_collection.schema.json} +5 -5
 - data/app/openbel/api/schemas/{evidence_resource.schema.json → nanopub_resource.schema.json} +4 -4
 - data/config/config.yml +15 -5
 - data/lib/openbel/api/helpers/uuid_generator.rb +22 -0
 - data/lib/openbel/api/{evidence → nanopub}/api.rb +9 -9
 - data/lib/openbel/api/{evidence → nanopub}/facet_api.rb +2 -2
 - data/lib/openbel/api/{evidence → nanopub}/facet_filter.rb +6 -6
 - data/lib/openbel/api/{evidence → nanopub}/mongo.rb +54 -52
 - data/lib/openbel/api/{evidence → nanopub}/mongo_facet.rb +17 -28
 - data/lib/openbel/api/plugin/{evidence/evidence.rb → nanopub/nanopub.rb} +7 -7
 - metadata +44 -56
 - data/app/openbel/api/routes/functions.rb +0 -41
 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "$schema": "http://json-schema.org/draft-04/schema",
         
     | 
| 
       3 
3 
     | 
    
         
             
              "title": "Annotation",
         
     | 
| 
       4 
     | 
    
         
            -
              "description": "A vocabulary of terms for describing  
     | 
| 
      
 4 
     | 
    
         
            +
              "description": "A vocabulary of terms for describing nanopub resources.",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "type": "object",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "additionalProperties": false,
         
     | 
| 
       7 
7 
     | 
    
         
             
              "required": [
         
     | 
| 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "$schema":              "http://json-schema.org/draft-04/schema",
         
     | 
| 
       3 
     | 
    
         
            -
              "description":          "DESCRIBE  
     | 
| 
      
 3 
     | 
    
         
            +
              "description":          "DESCRIBE NANOPUB",
         
     | 
| 
       4 
4 
     | 
    
         
             
              "type":                 "object",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "additionalProperties": false,
         
     | 
| 
       6 
     | 
    
         
            -
              "required":             [" 
     | 
| 
      
 6 
     | 
    
         
            +
              "required":             ["nanopub"],
         
     | 
| 
       7 
7 
     | 
    
         
             
              "properties": {
         
     | 
| 
       8 
     | 
    
         
            -
                " 
     | 
| 
      
 8 
     | 
    
         
            +
                "nanopub": {
         
     | 
| 
       9 
9 
     | 
    
         
             
                  "type":                 "object",
         
     | 
| 
       10 
10 
     | 
    
         
             
                  "additionalProperties": false,
         
     | 
| 
       11 
11 
     | 
    
         
             
                  "required":             ["bel_statement", "citation"],
         
     | 
| 
         @@ -92,10 +92,10 @@ 
     | 
|
| 
       92 
92 
     | 
    
         
             
                        }
         
     | 
| 
       93 
93 
     | 
    
         
             
                      }
         
     | 
| 
       94 
94 
     | 
    
         
             
                    },
         
     | 
| 
       95 
     | 
    
         
            -
                    " 
     | 
| 
      
 95 
     | 
    
         
            +
                    "support": {
         
     | 
| 
       96 
96 
     | 
    
         
             
                      "type":        ["string", "null"],
         
     | 
| 
       97 
     | 
    
         
            -
                      "title":       " 
     | 
| 
       98 
     | 
    
         
            -
                      "description": "Abstract from source text to provide support for this  
     | 
| 
      
 97 
     | 
    
         
            +
                      "title":       "Support",
         
     | 
| 
      
 98 
     | 
    
         
            +
                      "description": "Abstract from source text to provide support for this nanopub"
         
     | 
| 
       99 
99 
     | 
    
         
             
                    },
         
     | 
| 
       100 
100 
     | 
    
         
             
                    "references": {
         
     | 
| 
       101 
101 
     | 
    
         
             
                      "type":        ["object", "null"],
         
     | 
| 
         @@ -112,7 +112,7 @@ 
     | 
|
| 
       112 
112 
     | 
    
         
             
                              "keyword": {
         
     | 
| 
       113 
113 
     | 
    
         
             
                                "type":        "string",
         
     | 
| 
       114 
114 
     | 
    
         
             
                                "title":       "Keyword",
         
     | 
| 
       115 
     | 
    
         
            -
                                "description": "Keyword that identifies this annotation resource, but only in the context of this  
     | 
| 
      
 115 
     | 
    
         
            +
                                "description": "Keyword that identifies this annotation resource, but only in the context of this Nanopub."
         
     | 
| 
       116 
116 
     | 
    
         
             
                              },
         
     | 
| 
       117 
117 
     | 
    
         
             
                              "uri": {
         
     | 
| 
       118 
118 
     | 
    
         
             
                                "type":        "string",
         
     | 
| 
         @@ -134,7 +134,7 @@ 
     | 
|
| 
       134 
134 
     | 
    
         
             
                              "keyword": {
         
     | 
| 
       135 
135 
     | 
    
         
             
                                "type":        "string",
         
     | 
| 
       136 
136 
     | 
    
         
             
                                "title":       "Keyword",
         
     | 
| 
       137 
     | 
    
         
            -
                                "description": "Keyword that identifies this namespace resource, but only in the context of this  
     | 
| 
      
 137 
     | 
    
         
            +
                                "description": "Keyword that identifies this namespace resource, but only in the context of this Nanopub."
         
     | 
| 
       138 
138 
     | 
    
         
             
                              },
         
     | 
| 
       139 
139 
     | 
    
         
             
                              "uri": {
         
     | 
| 
       140 
140 
     | 
    
         
             
                                "type":        "string",
         
     | 
| 
         @@ -150,8 +150,8 @@ 
     | 
|
| 
       150 
150 
     | 
    
         
             
                    },
         
     | 
| 
       151 
151 
     | 
    
         
             
                    "metadata": {
         
     | 
| 
       152 
152 
     | 
    
         
             
                      "type":        ["array", "null"],
         
     | 
| 
       153 
     | 
    
         
            -
                      "title":       " 
     | 
| 
       154 
     | 
    
         
            -
                      "description": "Metadata that describes the  
     | 
| 
      
 153 
     | 
    
         
            +
                      "title":       "Nanopub resource metadata",
         
     | 
| 
      
 154 
     | 
    
         
            +
                      "description": "Metadata that describes the nanopub resource.",
         
     | 
| 
       155 
155 
     | 
    
         
             
                      "items": {
         
     | 
| 
       156 
156 
     | 
    
         
             
                        "oneOf": [
         
     | 
| 
       157 
157 
     | 
    
         
             
                          {
         
     | 
    
        data/app/openbel/api/schemas/{evidence_collection.schema.json → nanopub_collection.schema.json}
    RENAMED
    
    | 
         @@ -1,20 +1,20 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "$schema": "http://json-schema.org/draft-04/schema",
         
     | 
| 
       3 
     | 
    
         
            -
              "description": "DESCRIBE  
     | 
| 
      
 3 
     | 
    
         
            +
              "description": "DESCRIBE NANOPUB COLLECTION",
         
     | 
| 
       4 
4 
     | 
    
         
             
              "type": "object",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "additionalProperties": false,
         
     | 
| 
       6 
6 
     | 
    
         
             
              "required": [
         
     | 
| 
       7 
     | 
    
         
            -
                " 
     | 
| 
      
 7 
     | 
    
         
            +
                "nanopub_collection",
         
     | 
| 
       8 
8 
     | 
    
         
             
                "facets"
         
     | 
| 
       9 
9 
     | 
    
         
             
              ],
         
     | 
| 
       10 
10 
     | 
    
         
             
              "properties": {
         
     | 
| 
       11 
     | 
    
         
            -
                " 
     | 
| 
      
 11 
     | 
    
         
            +
                "nanopub_collection": {
         
     | 
| 
       12 
12 
     | 
    
         
             
                  "type": "array",
         
     | 
| 
       13 
13 
     | 
    
         
             
                  "minItems": 0,
         
     | 
| 
       14 
14 
     | 
    
         
             
                  "title": "",
         
     | 
| 
       15 
15 
     | 
    
         
             
                  "description": "",
         
     | 
| 
       16 
16 
     | 
    
         
             
                  "items": {
         
     | 
| 
       17 
     | 
    
         
            -
                    "$ref":" 
     | 
| 
      
 17 
     | 
    
         
            +
                    "$ref":"nanopub_resource.schema.json"
         
     | 
| 
       18 
18 
     | 
    
         
             
                  }
         
     | 
| 
       19 
19 
     | 
    
         
             
                },
         
     | 
| 
       20 
20 
     | 
    
         
             
                "facets": {
         
     | 
| 
         @@ -53,7 +53,7 @@ 
     | 
|
| 
       53 
53 
     | 
    
         
             
                },
         
     | 
| 
       54 
54 
     | 
    
         
             
                "metadata": {
         
     | 
| 
       55 
55 
     | 
    
         
             
                  "title": "Metadata",
         
     | 
| 
       56 
     | 
    
         
            -
                  "description": "Data about the  
     | 
| 
      
 56 
     | 
    
         
            +
                  "description": "Data about the nanopub collection",
         
     | 
| 
       57 
57 
     | 
    
         
             
                  "type": "object",
         
     | 
| 
       58 
58 
     | 
    
         
             
                  "additionalProperties": true,
         
     | 
| 
       59 
59 
     | 
    
         
             
                  "properties": {
         
     | 
| 
         @@ -1,16 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "$schema": "http://json-schema.org/draft-04/schema",
         
     | 
| 
       3 
     | 
    
         
            -
              "title": " 
     | 
| 
       4 
     | 
    
         
            -
              "description": "A single  
     | 
| 
      
 3 
     | 
    
         
            +
              "title": "Nanopub Resource",
         
     | 
| 
      
 4 
     | 
    
         
            +
              "description": "A single nanopub resource.",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "type": "object",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "additionalProperties": false,
         
     | 
| 
       7 
7 
     | 
    
         
             
              "required": [
         
     | 
| 
       8 
     | 
    
         
            -
                " 
     | 
| 
      
 8 
     | 
    
         
            +
                "nanopub"
         
     | 
| 
       9 
9 
     | 
    
         
             
              ],
         
     | 
| 
       10 
10 
     | 
    
         
             
              "properties": {
         
     | 
| 
       11 
11 
     | 
    
         
             
                "allOf": [
         
     | 
| 
       12 
12 
     | 
    
         
             
                  {
         
     | 
| 
       13 
     | 
    
         
            -
                    "$ref":" 
     | 
| 
      
 13 
     | 
    
         
            +
                    "$ref":"nanopub.schema.json"
         
     | 
| 
       14 
14 
     | 
    
         
             
                  },
         
     | 
| 
       15 
15 
     | 
    
         
             
                  {
         
     | 
| 
       16 
16 
     | 
    
         
             
                    "type": "object",
         
     | 
    
        data/config/config.yml
    CHANGED
    
    | 
         @@ -1,7 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Configuration template for OpenBEL API
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            #  
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # BEL configuration.
         
     | 
| 
      
 4 
     | 
    
         
            +
            bel:
         
     | 
| 
      
 5 
     | 
    
         
            +
              # The BEL version supported by this OpenBEL API instance.
         
     | 
| 
      
 6 
     | 
    
         
            +
              # Allowed values:
         
     | 
| 
      
 7 
     | 
    
         
            +
              #   1.0
         
     | 
| 
      
 8 
     | 
    
         
            +
              #     (BEL version 1.0 specification)
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
              #     (BEL version 2.0 specification)
         
     | 
| 
      
 11 
     | 
    
         
            +
              version: 2.0
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            # Storage of nanopubs through the Mongo database.
         
     | 
| 
      
 14 
     | 
    
         
            +
            nanopub_store:
         
     | 
| 
       5 
15 
     | 
    
         
             
              mongo:
         
     | 
| 
       6 
16 
     | 
    
         | 
| 
       7 
17 
     | 
    
         
             
                # The MongoDB host to connect to. For example if MongoDB's net.bindIp
         
     | 
| 
         @@ -12,9 +22,9 @@ evidence_store: 
     | 
|
| 
       12 
22 
     | 
    
         
             
                # The default MongoDB port. Configured under MongoDB's `net.port` setting.
         
     | 
| 
       13 
23 
     | 
    
         
             
                port:                     27017
         
     | 
| 
       14 
24 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                # The name of your database. We think "openbel- 
     | 
| 
      
 25 
     | 
    
         
            +
                # The name of your database. We think "openbel-nanopubs" should be fine,
         
     | 
| 
       16 
26 
     | 
    
         
             
                # but it's up to you.
         
     | 
| 
       17 
     | 
    
         
            -
                database:                 'openbel- 
     | 
| 
      
 27 
     | 
    
         
            +
                database:                 'openbel-nanopubs'
         
     | 
| 
       18 
28 
     | 
    
         | 
| 
       19 
29 
     | 
    
         
             
                # MongoDB authentication and role assignment. These settings are necessary
         
     | 
| 
       20 
30 
     | 
    
         
             
                # if you would like to have a MongoDB user authenticated and authorized to
         
     | 
| 
         @@ -23,7 +33,7 @@ evidence_store: 
     | 
|
| 
       23 
33 
     | 
    
         
             
                #First, you will need to create a MongoDB user with the "readWrite" and
         
     | 
| 
       24 
34 
     | 
    
         
             
                #"dbAdmin" roles for the "database" value set above. This is to allow read,
         
     | 
| 
       25 
35 
     | 
    
         
             
                #write, and index creation in the OpenBEL API application.
         
     | 
| 
       26 
     | 
    
         
            -
                #See https://github.com/OpenBEL/openbel-api/wiki/Configuring-the- 
     | 
| 
      
 36 
     | 
    
         
            +
                #See https://github.com/OpenBEL/openbel-api/wiki/Configuring-the-Nanopub-Store#adding-the-openbel-user
         
     | 
| 
       27 
37 
     | 
    
         
             
                #username:                'openbel-user'
         
     | 
| 
       28 
38 
     | 
    
         | 
| 
       29 
39 
     | 
    
         
             
                #Second, you will need to set a password for the MongoDB user set above.
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module OpenBEL
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Helpers
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Mixin to provide generation of String UUIDs.
         
     | 
| 
      
 4 
     | 
    
         
            +
                #
         
     | 
| 
      
 5 
     | 
    
         
            +
                # The {#generate_uuid} instance method is available with a
         
     | 
| 
      
 6 
     | 
    
         
            +
                # platform-specific implementation.
         
     | 
| 
      
 7 
     | 
    
         
            +
                module UUIDGenerator
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # Define UUID implementation based on Ruby.
         
     | 
| 
      
 9 
     | 
    
         
            +
                  if RUBY_ENGINE =~ /^jruby/i
         
     | 
| 
      
 10 
     | 
    
         
            +
                    java_import 'java.util.UUID'
         
     | 
| 
      
 11 
     | 
    
         
            +
                    define_method(:generate_uuid) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                      Java::JavaUtil::UUID.random_uuid.to_s
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  else
         
     | 
| 
      
 15 
     | 
    
         
            +
                    require 'uuid'
         
     | 
| 
      
 16 
     | 
    
         
            +
                    define_method(:generate_uuid) do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      UUID.generate
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,17 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module OpenBEL
         
     | 
| 
       2 
     | 
    
         
            -
              module  
     | 
| 
      
 2 
     | 
    
         
            +
              module Nanopub
         
     | 
| 
       3 
3 
     | 
    
         
             
                module API
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                  # single or array
         
     | 
| 
       6 
     | 
    
         
            -
                  def  
     | 
| 
      
 6 
     | 
    
         
            +
                  def create_nanopub(nanopub)
         
     | 
| 
       7 
7 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       8 
8 
     | 
    
         
             
                  end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  def  
     | 
| 
      
 10 
     | 
    
         
            +
                  def find_nanopub_by_id(id)
         
     | 
| 
       11 
11 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       12 
12 
     | 
    
         
             
                  end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                  def  
     | 
| 
      
 14 
     | 
    
         
            +
                  def find_nanopub(filters = [], offset = 0, length = 0, facet = false)
         
     | 
| 
       15 
15 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
         @@ -23,23 +23,23 @@ module OpenBEL 
     | 
|
| 
       23 
23 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       24 
24 
     | 
    
         
             
                  end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                  def  
     | 
| 
      
 26 
     | 
    
         
            +
                  def count_nanopub(filters = [])
         
     | 
| 
       27 
27 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       28 
28 
     | 
    
         
             
                  end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                  def  
     | 
| 
      
 30 
     | 
    
         
            +
                  def update_nanopub_by_id(id, nanopub_update)
         
     | 
| 
       31 
31 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                  def  
     | 
| 
      
 34 
     | 
    
         
            +
                  def update_nanopub_by_query(query, nanopub_update)
         
     | 
| 
       35 
35 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                  def  
     | 
| 
      
 38 
     | 
    
         
            +
                  def delete_nanopub_by_id(id)
         
     | 
| 
       39 
39 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       40 
40 
     | 
    
         
             
                  end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
                  def  
     | 
| 
      
 42 
     | 
    
         
            +
                  def delete_nanopub_by_query(query)
         
     | 
| 
       43 
43 
     | 
    
         
             
                    fail NotImplementedError, "#{__method__} is not implemented"
         
     | 
| 
       44 
44 
     | 
    
         
             
                  end
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,16 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'multi_json'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module OpenBEL
         
     | 
| 
       4 
     | 
    
         
            -
              module  
     | 
| 
      
 4 
     | 
    
         
            +
              module Nanopub
         
     | 
| 
       5 
5 
     | 
    
         
             
                module FacetFilter
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                  EMPTY = []
         
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
      
 8 
     | 
    
         
            +
                  NANOPUB_PARTS = [:citation, :experiment_context, :metadata]
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  def  
     | 
| 
       11 
     | 
    
         
            -
                     
     | 
| 
       12 
     | 
    
         
            -
                      part =  
     | 
| 
       13 
     | 
    
         
            -
                      new_facets = self.send(:"map_#{ 
     | 
| 
      
 10 
     | 
    
         
            +
                  def map_nanopub_facets(nanopub)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    NANOPUB_PARTS.reduce([]) { |facets, nanopub_part|
         
     | 
| 
      
 12 
     | 
    
         
            +
                      part = nanopub.send(nanopub_part)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      new_facets = self.send(:"map_#{nanopub_part}_facets", part)
         
     | 
| 
       14 
14 
     | 
    
         
             
                      facets.concat(new_facets)
         
     | 
| 
       15 
15 
     | 
    
         
             
                    }
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,13 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'bel'
         
     | 
| 
       2 
     | 
    
         
            -
            require ' 
     | 
| 
      
 2 
     | 
    
         
            +
            require 'bel_parser/expression/model'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'bel/nanopub/util'
         
     | 
| 
       3 
4 
     | 
    
         
             
            require 'mongo'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative 'api'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require_relative 'mongo_facet'
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
            module OpenBEL
         
     | 
| 
       8 
     | 
    
         
            -
              module  
     | 
| 
      
 9 
     | 
    
         
            +
              module Nanopub
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                class  
     | 
| 
      
 11 
     | 
    
         
            +
                class Nanopub
         
     | 
| 
       11 
12 
     | 
    
         
             
                  include API
         
     | 
| 
       12 
13 
     | 
    
         
             
                  include Mongo
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
         @@ -30,42 +31,42 @@ module OpenBEL 
     | 
|
| 
       30 
31 
     | 
    
         
             
                      @db.authenticate(username, password, nil, auth_db)
         
     | 
| 
       31 
32 
     | 
    
         
             
                    end
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                    @collection      = @db[: 
     | 
| 
       34 
     | 
    
         
            -
                    @ 
     | 
| 
      
 34 
     | 
    
         
            +
                    @collection      = @db[:nanopub]
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @nanopub_facets = NanopubFacets.new(options)
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
37 
     | 
    
         
             
                    # ensure all indexes are created and maintained
         
     | 
| 
       37 
38 
     | 
    
         
             
                    ensure_all_indexes
         
     | 
| 
       38 
39 
     | 
    
         
             
                  end
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                  def  
     | 
| 
       41 
     | 
    
         
            -
                    # insert  
     | 
| 
       42 
     | 
    
         
            -
                    if  
     | 
| 
       43 
     | 
    
         
            -
                      _id = @collection.insert( 
     | 
| 
      
 41 
     | 
    
         
            +
                  def create_nanopub(nanopub)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    # insert nanopub; acknowledge journal
         
     | 
| 
      
 43 
     | 
    
         
            +
                    if nanopub.respond_to?(:each_pair)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      _id = @collection.insert(nanopub, :w => 1, :j => true)
         
     | 
| 
       44 
45 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                      # remove  
     | 
| 
       46 
     | 
    
         
            -
                       
     | 
| 
      
 46 
     | 
    
         
            +
                      # remove nanopub_facets after insert to facets
         
     | 
| 
      
 47 
     | 
    
         
            +
                      remove_nanopub_facets(_id)
         
     | 
| 
       47 
48 
     | 
    
         
             
                      _id
         
     | 
| 
       48 
     | 
    
         
            -
                    elsif  
     | 
| 
       49 
     | 
    
         
            -
                      @collection.insert( 
     | 
| 
      
 49 
     | 
    
         
            +
                    elsif nanopub.respond_to?(:each)
         
     | 
| 
      
 50 
     | 
    
         
            +
                      @collection.insert(nanopub.to_a, :w => 1, :j => true)
         
     | 
| 
       50 
51 
     | 
    
         
             
                    else
         
     | 
| 
       51 
     | 
    
         
            -
                      raise " 
     | 
| 
      
 52 
     | 
    
         
            +
                      raise "nanopub type #{nanopub.class} cannot be inserted into Mongo."
         
     | 
| 
       52 
53 
     | 
    
         
             
                    end
         
     | 
| 
       53 
54 
     | 
    
         
             
                  end
         
     | 
| 
       54 
55 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                  def  
     | 
| 
      
 56 
     | 
    
         
            +
                  def find_nanopub_by_id(value)
         
     | 
| 
       56 
57 
     | 
    
         
             
                    @collection.find_one(to_id(value))
         
     | 
| 
       57 
58 
     | 
    
         
             
                  end
         
     | 
| 
       58 
59 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                  def  
     | 
| 
      
 60 
     | 
    
         
            +
                  def find_nanopub(filters = [], offset = 0, length = 0, facet = false, facet_value_limit = -1)
         
     | 
| 
       60 
61 
     | 
    
         
             
                    if includes_fts_search?(filters)
         
     | 
| 
       61 
62 
     | 
    
         
             
                      text_search = get_fts_search(filters)
         
     | 
| 
       62 
     | 
    
         
            -
                       
     | 
| 
      
 63 
     | 
    
         
            +
                      nanopub_aggregate(text_search, filters, offset, length, facet, facet_value_limit)
         
     | 
| 
       63 
64 
     | 
    
         
             
                    else
         
     | 
| 
       64 
     | 
    
         
            -
                       
     | 
| 
      
 65 
     | 
    
         
            +
                      nanopub_query(filters, offset, length, facet, facet_value_limit)
         
     | 
| 
       65 
66 
     | 
    
         
             
                    end
         
     | 
| 
       66 
67 
     | 
    
         
             
                  end
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                  def  
     | 
| 
      
 69 
     | 
    
         
            +
                  def find_dataset_nanopub(dataset, filters = [], offset = 0, length = 0, facet = false, facet_value_limit = -1)
         
     | 
| 
       69 
70 
     | 
    
         
             
                    query_hash = to_query(filters)
         
     | 
| 
       70 
71 
     | 
    
         
             
                    query_hash[:$and] ||= []
         
     | 
| 
       71 
72 
     | 
    
         
             
                    query_hash[:$and].unshift({
         
     | 
| 
         @@ -85,7 +86,7 @@ module OpenBEL 
     | 
|
| 
       85 
86 
     | 
    
         
             
                      :cursor => @collection.find(query_hash, query_opts)
         
     | 
| 
       86 
87 
     | 
    
         
             
                    }
         
     | 
| 
       87 
88 
     | 
    
         
             
                    if facet
         
     | 
| 
       88 
     | 
    
         
            -
                      facets_cursor = @ 
     | 
| 
      
 89 
     | 
    
         
            +
                      facets_cursor = @nanopub_facets.find_facets(query_hash, filters, facet_value_limit)
         
     | 
| 
       89 
90 
     | 
    
         
             
                      results[:facets] = facets_cursor.to_a
         
     | 
| 
       90 
91 
     | 
    
         
             
                    end
         
     | 
| 
       91 
92 
     | 
    
         | 
| 
         @@ -103,7 +104,7 @@ module OpenBEL 
     | 
|
| 
       103 
104 
     | 
    
         
             
                        {
         
     | 
| 
       104 
105 
     | 
    
         
             
                          :$unwind => "$references.namespaces"
         
     | 
| 
       105 
106 
     | 
    
         
             
                        },
         
     | 
| 
       106 
     | 
    
         
            -
                        { 
     | 
| 
      
 107 
     | 
    
         
            +
                        {
         
     | 
| 
       107 
108 
     | 
    
         
             
                          :$project => {
         
     | 
| 
       108 
109 
     | 
    
         
             
                            keyword: "$references.namespaces.keyword",
         
     | 
| 
       109 
110 
     | 
    
         
             
                            uri: "$references.namespaces.uri"
         
     | 
| 
         @@ -137,7 +138,7 @@ module OpenBEL 
     | 
|
| 
       137 
138 
     | 
    
         
             
                      obj = obj.to_h
         
     | 
| 
       138 
139 
     | 
    
         
             
                      obj[:keyword] = obj.delete("keyword")
         
     | 
| 
       139 
140 
     | 
    
         
             
                      obj[:uri]     = obj.delete("uri")
         
     | 
| 
       140 
     | 
    
         
            -
                      union, new_remap = BEL:: 
     | 
| 
      
 141 
     | 
    
         
            +
                      union, new_remap = BEL::Nanopub.union_namespace_references(union, [obj], 'incr')
         
     | 
| 
       141 
142 
     | 
    
         
             
                      remap.merge!(new_remap)
         
     | 
| 
       142 
143 
     | 
    
         
             
                    end
         
     | 
| 
       143 
144 
     | 
    
         | 
| 
         @@ -153,7 +154,7 @@ module OpenBEL 
     | 
|
| 
       153 
154 
     | 
    
         
             
                        {
         
     | 
| 
       154 
155 
     | 
    
         
             
                          :$unwind => "$references.annotations"
         
     | 
| 
       155 
156 
     | 
    
         
             
                        },
         
     | 
| 
       156 
     | 
    
         
            -
                        { 
     | 
| 
      
 157 
     | 
    
         
            +
                        {
         
     | 
| 
       157 
158 
     | 
    
         
             
                          :$project => {
         
     | 
| 
       158 
159 
     | 
    
         
             
                            keyword: "$references.annotations.keyword",
         
     | 
| 
       159 
160 
     | 
    
         
             
                            type:    "$references.annotations.type",
         
     | 
| 
         @@ -192,38 +193,39 @@ module OpenBEL 
     | 
|
| 
       192 
193 
     | 
    
         
             
                    union = []
         
     | 
| 
       193 
194 
     | 
    
         
             
                    remap = {}
         
     | 
| 
       194 
195 
     | 
    
         
             
                    references.each do |obj|
         
     | 
| 
       195 
     | 
    
         
            -
                       
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
                      union, new_remap = 
     | 
| 
      
 196 
     | 
    
         
            +
                      annotation =
         
     | 
| 
      
 197 
     | 
    
         
            +
                        BELParser::Expression::Model::Annotation.new(
         
     | 
| 
      
 198 
     | 
    
         
            +
                          *obj.values_at('keyword', 'type', 'domain')
         
     | 
| 
      
 199 
     | 
    
         
            +
                        )
         
     | 
| 
      
 200 
     | 
    
         
            +
                      union, new_remap =
         
     | 
| 
      
 201 
     | 
    
         
            +
                        BEL::Nanopub.union_annotation_references(union, [annotation], 'incr')
         
     | 
| 
       200 
202 
     | 
    
         
             
                      remap.merge!(new_remap)
         
     | 
| 
       201 
203 
     | 
    
         
             
                    end
         
     | 
| 
       202 
204 
     | 
    
         | 
| 
       203 
205 
     | 
    
         
             
                    remap
         
     | 
| 
       204 
206 
     | 
    
         
             
                  end
         
     | 
| 
       205 
207 
     | 
    
         | 
| 
       206 
     | 
    
         
            -
                  def  
     | 
| 
      
 208 
     | 
    
         
            +
                  def count_nanopub(filters = [])
         
     | 
| 
       207 
209 
     | 
    
         
             
                    query_hash = to_query(filters)
         
     | 
| 
       208 
210 
     | 
    
         
             
                    @collection.count(:query => query_hash)
         
     | 
| 
       209 
211 
     | 
    
         
             
                  end
         
     | 
| 
       210 
212 
     | 
    
         | 
| 
       211 
     | 
    
         
            -
                  def  
     | 
| 
      
 213 
     | 
    
         
            +
                  def update_nanopub_by_id(value, nanopub)
         
     | 
| 
       212 
214 
     | 
    
         
             
                    # add ObjectId to update
         
     | 
| 
       213 
215 
     | 
    
         
             
                    _id = BSON::ObjectId(value)
         
     | 
| 
       214 
     | 
    
         
            -
                     
     | 
| 
       215 
     | 
    
         
            -
                     
     | 
| 
      
 216 
     | 
    
         
            +
                    nanopub_h = nanopub.to_h
         
     | 
| 
      
 217 
     | 
    
         
            +
                    nanopub_h[:_id] = _id
         
     | 
| 
       216 
218 
     | 
    
         | 
| 
       217 
     | 
    
         
            -
                    # save  
     | 
| 
       218 
     | 
    
         
            -
                    @collection.save( 
     | 
| 
      
 219 
     | 
    
         
            +
                    # save nanopub; acknowledge journal
         
     | 
| 
      
 220 
     | 
    
         
            +
                    @collection.save(nanopub_h, :j => true)
         
     | 
| 
       219 
221 
     | 
    
         | 
| 
       220 
     | 
    
         
            -
                    # remove  
     | 
| 
       221 
     | 
    
         
            -
                     
     | 
| 
      
 222 
     | 
    
         
            +
                    # remove nanopub_facets after update to facets
         
     | 
| 
      
 223 
     | 
    
         
            +
                    remove_nanopub_facets(_id)
         
     | 
| 
       222 
224 
     | 
    
         
             
                    nil
         
     | 
| 
       223 
225 
     | 
    
         
             
                  end
         
     | 
| 
       224 
226 
     | 
    
         | 
| 
       225 
227 
     | 
    
         
             
                  def delete_facets
         
     | 
| 
       226 
     | 
    
         
            -
                    @ 
     | 
| 
      
 228 
     | 
    
         
            +
                    @nanopub_facets.delete_all_facets
         
     | 
| 
       227 
229 
     | 
    
         
             
                  end
         
     | 
| 
       228 
230 
     | 
    
         | 
| 
       229 
231 
     | 
    
         
             
                  def delete_dataset(identifier)
         
     | 
| 
         @@ -231,27 +233,27 @@ module OpenBEL 
     | 
|
| 
       231 
233 
     | 
    
         
             
                      { :"_dataset" => identifier },
         
     | 
| 
       232 
234 
     | 
    
         
             
                      :j => true
         
     | 
| 
       233 
235 
     | 
    
         
             
                    )
         
     | 
| 
       234 
     | 
    
         
            -
                    @ 
     | 
| 
      
 236 
     | 
    
         
            +
                    @nanopub_facets.delete_all_facets
         
     | 
| 
       235 
237 
     | 
    
         
             
                  end
         
     | 
| 
       236 
238 
     | 
    
         | 
| 
       237 
     | 
    
         
            -
                  def  
     | 
| 
      
 239 
     | 
    
         
            +
                  def delete_nanopub(value)
         
     | 
| 
       238 
240 
     | 
    
         
             
                    if value.respond_to?(:each)
         
     | 
| 
       239 
241 
     | 
    
         
             
                      value.each do |v|
         
     | 
| 
       240 
     | 
    
         
            -
                         
     | 
| 
      
 242 
     | 
    
         
            +
                        delete_nanopub_by_id(v)
         
     | 
| 
       241 
243 
     | 
    
         
             
                      end
         
     | 
| 
       242 
244 
     | 
    
         
             
                    else
         
     | 
| 
       243 
     | 
    
         
            -
                       
     | 
| 
      
 245 
     | 
    
         
            +
                      delete_nanopub_by_id(value)
         
     | 
| 
       244 
246 
     | 
    
         
             
                    end
         
     | 
| 
       245 
247 
     | 
    
         
             
                  end
         
     | 
| 
       246 
248 
     | 
    
         | 
| 
       247 
     | 
    
         
            -
                  def  
     | 
| 
      
 249 
     | 
    
         
            +
                  def delete_nanopub_by_query(query)
         
     | 
| 
       248 
250 
     | 
    
         
             
                    @collection.remove(
         
     | 
| 
       249 
251 
     | 
    
         
             
                      query,
         
     | 
| 
       250 
252 
     | 
    
         
             
                      :j => true
         
     | 
| 
       251 
253 
     | 
    
         
             
                    )
         
     | 
| 
       252 
254 
     | 
    
         
             
                  end
         
     | 
| 
       253 
255 
     | 
    
         | 
| 
       254 
     | 
    
         
            -
                  def  
     | 
| 
      
 256 
     | 
    
         
            +
                  def delete_nanopub_by_id(value)
         
     | 
| 
       255 
257 
     | 
    
         
             
                    # convert to ObjectId
         
     | 
| 
       256 
258 
     | 
    
         
             
                    begin
         
     | 
| 
       257 
259 
     | 
    
         
             
                      _id = to_id(value)
         
     | 
| 
         @@ -260,10 +262,10 @@ module OpenBEL 
     | 
|
| 
       260 
262 
     | 
    
         
             
                      false
         
     | 
| 
       261 
263 
     | 
    
         
             
                    end
         
     | 
| 
       262 
264 
     | 
    
         | 
| 
       263 
     | 
    
         
            -
                    # remove  
     | 
| 
       264 
     | 
    
         
            -
                     
     | 
| 
      
 265 
     | 
    
         
            +
                    # remove nanopub_facets before nanopub removal
         
     | 
| 
      
 266 
     | 
    
         
            +
                    remove_nanopub_facets(_id)
         
     | 
| 
       265 
267 
     | 
    
         | 
| 
       266 
     | 
    
         
            -
                    # remove  
     | 
| 
      
 268 
     | 
    
         
            +
                    # remove nanopub; returns true
         
     | 
| 
       267 
269 
     | 
    
         
             
                    @collection.remove(
         
     | 
| 
       268 
270 
     | 
    
         
             
                      {
         
     | 
| 
       269 
271 
     | 
    
         
             
                          :_id => _id
         
     | 
| 
         @@ -297,7 +299,7 @@ module OpenBEL 
     | 
|
| 
       297 
299 
     | 
    
         | 
| 
       298 
300 
     | 
    
         
             
                  private
         
     | 
| 
       299 
301 
     | 
    
         | 
| 
       300 
     | 
    
         
            -
                  def  
     | 
| 
      
 302 
     | 
    
         
            +
                  def nanopub_query(filters = [], offset = 0, length = 0, facet = false, facet_value_limit = -1)
         
     | 
| 
       301 
303 
     | 
    
         
             
                    query_hash = to_query(filters)
         
     | 
| 
       302 
304 
     | 
    
         
             
                    query_opts = query_options(
         
     | 
| 
       303 
305 
     | 
    
         
             
                      query_hash,
         
     | 
| 
         @@ -312,14 +314,14 @@ module OpenBEL 
     | 
|
| 
       312 
314 
     | 
    
         
             
                      :cursor => @collection.find(query_hash, query_opts)
         
     | 
| 
       313 
315 
     | 
    
         
             
                    }
         
     | 
| 
       314 
316 
     | 
    
         
             
                    if facet
         
     | 
| 
       315 
     | 
    
         
            -
                      facets_cursor = @ 
     | 
| 
      
 317 
     | 
    
         
            +
                      facets_cursor = @nanopub_facets.find_facets(query_hash, filters, facet_value_limit)
         
     | 
| 
       316 
318 
     | 
    
         
             
                      results[:facets] = facets_cursor.to_a
         
     | 
| 
       317 
319 
     | 
    
         
             
                    end
         
     | 
| 
       318 
320 
     | 
    
         | 
| 
       319 
321 
     | 
    
         
             
                    results
         
     | 
| 
       320 
322 
     | 
    
         
             
                  end
         
     | 
| 
       321 
323 
     | 
    
         | 
| 
       322 
     | 
    
         
            -
                  def  
     | 
| 
      
 324 
     | 
    
         
            +
                  def nanopub_aggregate(text_search, filters = [], offset = 0, length = 0, facet = false, facet_value_limit = -1)
         
     | 
| 
       323 
325 
     | 
    
         
             
                    match_filters = filters.select { |filter|
         
     | 
| 
       324 
326 
     | 
    
         
             
                      filter['category'] != 'fts'
         
     | 
| 
       325 
327 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -376,7 +378,7 @@ module OpenBEL 
     | 
|
| 
       376 
378 
     | 
    
         
             
                    facets =
         
     | 
| 
       377 
379 
     | 
    
         
             
                      if facet
         
     | 
| 
       378 
380 
     | 
    
         
             
                        query_hash = to_query(filters)
         
     | 
| 
       379 
     | 
    
         
            -
                        facets_cursor = @ 
     | 
| 
      
 381 
     | 
    
         
            +
                        facets_cursor = @nanopub_facets.find_facets(query_hash, filters, facet_value_limit)
         
     | 
| 
       380 
382 
     | 
    
         
             
                        facets_cursor.to_a
         
     | 
| 
       381 
383 
     | 
    
         
             
                      else
         
     | 
| 
       382 
384 
     | 
    
         
             
                        nil
         
     | 
| 
         @@ -498,13 +500,13 @@ module OpenBEL 
     | 
|
| 
       498 
500 
     | 
    
         
             
                    BSON::ObjectId(value.to_s)
         
     | 
| 
       499 
501 
     | 
    
         
             
                  end
         
     | 
| 
       500 
502 
     | 
    
         | 
| 
       501 
     | 
    
         
            -
                  def  
     | 
| 
      
 503 
     | 
    
         
            +
                  def remove_nanopub_facets(_id)
         
     | 
| 
       502 
504 
     | 
    
         
             
                    doc = @collection.find_one(_id, {
         
     | 
| 
       503 
505 
     | 
    
         
             
                      :fields => {:_id => 0, :facets => 1}
         
     | 
| 
       504 
506 
     | 
    
         
             
                    })
         
     | 
| 
       505 
507 
     | 
    
         | 
| 
       506 
508 
     | 
    
         
             
                    if doc && doc.has_key?('facets')
         
     | 
| 
       507 
     | 
    
         
            -
                      @ 
     | 
| 
      
 509 
     | 
    
         
            +
                      @nanopub_facets.delete_facets(doc['facets'])
         
     | 
| 
       508 
510 
     | 
    
         
             
                    end
         
     | 
| 
       509 
511 
     | 
    
         
             
                  end
         
     | 
| 
       510 
512 
     | 
    
         
             
                end
         
     |