示例#1
0
        /// <summary>
        /// Creates a new instance of <see cref="WikiDataHelper"/>.
        /// </summary>
        /// <param name="api">The WikiData API encapsulation.</param>
        public WikiDataHelper(WikibaseApi api)
        {
            if ( api == null )
                throw new ArgumentNullException("api");
            Api = api;
            _entityProvider = new EntityProvider(Api);

            var entities = GlobalData.CompleteGeocodeList();
            _allEntities = entities.FlatList();
        }
示例#2
0
        internal static Entity newFromArray(WikibaseApi api, JsonObject data)
        {
            if (data.get("type") != null)
            {
                switch (data.get("type").asString())
                {
                case "item":
                    return(new Item(api, data));

                case "property":
                    return(new Property(api, data));
                }
            }
            throw new Exception("Unknown type");
        }
示例#3
0
 internal Entity(WikibaseApi api, JsonObject data)
 {
     this.api = api;
     this.fillData(data);
 }
示例#4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Entity(WikibaseApi api) : this(api, new JsonObject()) { }
示例#5
0
 internal static Entity newFromArray(WikibaseApi api, JsonObject data)
 {
     if (data.get("type") != null)
     {
         switch (data.get("type").asString())
         {
             case "item":
                 return new Item(api, data);
             case "property":
                 return new Property(api, data);
         }
     }
     throw new Exception("Unknown type");
 }
示例#6
0
 internal Item(WikibaseApi api, JsonObject data) : base(api, data)
 {
 }
示例#7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Item(WikibaseApi api) : base(api)
 {
 }
示例#8
0
 internal Property(WikibaseApi api, JsonObject data) : base(api, data) { }
示例#9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Item(WikibaseApi api) : base(api) { }
示例#10
0
 internal Entity(WikibaseApi api, JsonObject data)
 {
     this.api = api;
     this.fillData(data);
 }
示例#11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Entity(WikibaseApi api) : this(api, new JsonObject())
 {
 }
示例#12
0
        private Dictionary<Entity, String> RetrieveWikpediaLinks(IEnumerable<Entity> entities, Language language)
        {
            var result = new Dictionary<Entity, String>();
            var api = new WikibaseApi("https://www.wikidata.org", "TambonBot");
            var helper = new WikiDataHelper(api);
            foreach ( var entity in entities.Where(x => x.wiki != null && !String.IsNullOrEmpty(x.wiki.wikidata)) )
            {
                var item = helper.GetWikiDataItemForEntity(entity);
                if ( item != null )
                {
                    var links = item.getSitelinks();
                    String languageLink;
                    String wikiIdentifier = String.Empty;
                    switch ( language )
                    {
                        case Language.German:
                            wikiIdentifier = "dewiki";
                            break;

                        case Language.English:
                            wikiIdentifier = "enwiki";
                            break;

                        case Language.Thai:
                            wikiIdentifier = "thwiki";
                            break;
                    }
                    if ( item.getSitelinks().TryGetValue(wikiIdentifier, out languageLink) )
                    {
                        result[entity] = languageLink;
                    }
                }
            }
            return result;
        }
示例#13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public EntityProvider(WikibaseApi api)
 {
     this.api = api;
 }
示例#14
0
 internal Item(WikibaseApi api, JsonObject data) : base(api, data) { }
示例#15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Property(WikibaseApi api) : base(api)
 {
 }
示例#16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public Property(WikibaseApi api) : base(api) { }
示例#17
0
 internal Property(WikibaseApi api, JsonObject data) : base(api, data)
 {
 }
示例#18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="api">The api</param>
 public EntityProvider(WikibaseApi api)
 {
     this.api = api;
 }