As described here, Pandoc records Synctex-like information when the source is commonmark+sourcepos. For example, with this commonmark input,
---
title: "Sample"
---
This is a sample document.
the output in native format starts like this:
Pandoc
Meta
{ unMeta =
fromList [ ( "title" , MetaInlines [ Str "Sample" ] ) ]
}
[ Div
( "" , [] , [ ( "data-pos" , "Sample.knit.md#5:1-6:1" ) ] )
[ Para
[ Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:1-5:5" ) ]
)
[ Str "This" ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:5-5:6" ) ]
)
[ Space ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:6-5:8" ) ]
)
[ Str "is" ]
but all that appears in the .tex file is this:
{This}{ }{is}...
As a step towards Synctex support, I'd like to insert the data-pos information as LaTeX markup, i.e. change the .tex output to look like this:
{This\datapos{Sample.knit.md#5:1-5:5}}{ \datapos{Sample.knit.md#5:5-5:6}}{is\datapos{Sample.knit.md#5:6-5:8}}...
This looks like something a Lua filter could accomplish pretty easily: look for the data-pos records, copy the location information into the Str record. However, I don't know Lua or Pandoc native language. Could someone help with this? Doing it for the Span records would be enough for my purposes. I'm using Pandoc 2.18 and Lua 5.4.
Here is an attempt that appears to work. Comments or corrections would still be welcome!
Span = function(span)
local datapos = span.attributes['data-pos']
if datapos then
table.insert(span.content, pandoc.RawInline('tex', "\\datapos{" .. datapos .. "}"))
end
return span
end
Given this string:
one#two*three#four#five*
What is a fast solution to extract the list of Pairs?
Each pair contains the word with its separator character like this:
[
['one', '#'],
['two', '*'],
['three', '#'],
['four', '#'],
['five', '*']
]
Specifically in my case I want to use both white space and new line characters as separators.
You'd need a regular expression:
(\w+)([#|*])
See example Dart code here that should get you going: https://dartpad.dartlang.org/ae3897b2221a94b5a4c9e6929bebcfce
Full disclosure: dart is a relatively new language to me.
That said, regex might be your best bet. Assuming you are only working with lowercase a-z letters followed by a single character, this should do the trick.
RegExp r = RegExp("([a-z]+)(.)");
var matches = r.allMatches("one#two*three#four#five*");
List<dynamic> l = [];
matches.toList().asMap().forEach((i, m) => l.add([m.group(1), m.group(2)]));
print(l);
Based on other responses here's my solution for white spaces and new lines as separators:
void main() {
RegExp r = RegExp(r"(\S+)([\s]+|$)");
var text = 'one two three \n\n four ';
var matches = r.allMatches(text);
List<dynamic> l = [];
matches.toList().asMap().forEach((i, m) => l.add([m.group(1), m.group(2)]));
print(l);
}
Output
[[one, ], [two, ], [three,
], [four, ]]
Explanation: https://regex101.com/r/cRpMVq/2
I have successfully loaded other ArcGIS shapefiles e.g., river polygon.However I am trying to draw/ create links by loading a polyline shapefile. Here is an extract of the code.
set river_area gis:load-dataset "River_data/April_28_2018_800m_Lines.shp"
set river_zones gis:load-dataset "River_data/May 5 2018_River_polygon_Zones.shp"
set polylines_links gis:load-dataset "River_data/Milford_Possible_routes_Polylines.shp"
Below is the code (from another source)for creating links and nodes. How can I modify it to work on the code that I am developing ?
foreach polylines-of polylines_links node-precision [
(foreach butlast ? butfirst ? [ if ?1 != ?2 [
let n1 new-node-at first ?1 last ?1
let n2 new-node-at first ?2 last ?2
ask n1 [create-link-with n2]
]])
]
I guess this is what you are looking for. Happy coding!
foreach polylines-of polylines_links node-precision [
x ->
(foreach butlast x butfirst x [
[a b] -> if a != b
[
let n1 new-node-at first a last a
let n2 new-node-at first b last b
ask n1 [create-link-with n2]
]
])
]
This question already has an answer here:
Compare two maps and find differences using Groovy or Java
(1 answer)
Closed 6 years ago.
I have two maps and I would like to combine this maps into new map with the differences. I mean with differences is if startDate or appId are different for that cuInfo and service.
Notice: The attributes cuInfo and service are unique in both maps.
Map 1:
[
[name:"Apple",cuInfo:"T12",service:"3",startDate:"14-02-16 10:00",appId:"G12351"],
[name:"Apple",cuInfo:"T13",service:"3",startDate:"14-01-16 13:00",appId:"G12352"],
[name:"Apple",cuInfo:"T16",service:"3",startDate:"14-01-16 13:00",appId:"G12353"],
[name:"Google",cuInfo:"T14",service:"9",startDate:"10-01-16 11:20",appId:"G12301"],
[name:"Microsoft",cuInfo:"T15",service:"10",startDate:"26-02-16 10:20",appId:"G12999"]
]
Map 2:
[
[cuInfo:"T12",service:"3",startDate:"14-01-16 13:22",appId:"G12355"],
[cuInfo:"T13",service:"3",startDate:"12-02-16 13:00",appId:"G12356"],
[cuInfo:"T14",service:"9",startDate:"10-01-16 11:20",appId:"G12300"],
[cuInfo:"T15",service:"10",startDate:"26-02-16 10:20",appId:"G12999"]
]
I would like to get map below as final result:
[
[name:"Apple",cuInfo:"T12",service:"3",startDate:"14-02-16 10:00",appId:"G12351",startDate2:"14-01-16 13:22",appId2:"G12355"],
[name:"Apple",cuInfo:"T13",service:"3",startDate:"14-01-16 13:00",appId:"G12352",startDate2:"12-02-16 13:00",appId2:"G12356"],
[name:"Google",cuInfo:"T14",service:"9",startDate:"10-01-16 11:20",appId:"G12301",startDate2:"10-01-16 11:20",appId2:"G12300"]
]
I tried the code below but it gives not what I want:
def total = [list1: list1, list2: list2].collectEntries { label, maps ->
[(label): maps.countBy { it.iccId} ]
}.inject([:]) { result, label, counts ->
counts.entrySet().each { entry ->
if(!result[entry.key]) result[entry.key] = [:]
result[entry.key][(label)] = entry.value
}
result
}.collect { iccId , counts -> [iccId: iccId] << counts }
The code above give me this, it merge the maps and count the cuInfos but I'm not able to get the differences:
[
[cuInfo:T12, list1:1, list2:1], [cuInfo:T13, list1:1, list2:1], [cuInfo:T14, list1:1, list2:1], [cuInfo:T15, list1:1, list2:1],[cuInfo:T16, list1:1]
]
Please who can help to get it work please with example. Thanks
Is that what you're looking for:
def col1 = [
[name:"Apple",cuInfo:"T12",service:"3",startDate:"14-02-16 10:00",appId:"G12351"],
[name:"Apple",cuInfo:"T13",service:"3",startDate:"14-01-16 13:00",appId:"G12352"],
[name:"Apple",cuInfo:"T16",service:"3",startDate:"14-01-16 13:00",appId:"G12353"],
[name:"Google",cuInfo:"T14",service:"9",startDate:"10-01-16 11:20",appId:"G12301"],
[name:"Microsoft",cuInfo:"T15",service:"10",startDate:"26-02-16 10:20",appId:"G12999"]
]
def col2 = [
[cuInfo:"T12",service:"3",startDate:"14-01-16 13:22",appId:"G12355"],
[cuInfo:"T13",service:"3",startDate:"12-02-16 13:00",appId:"G12356"],
[cuInfo:"T14",service:"9",startDate:"10-01-16 11:20",appId:"G12300"],
[cuInfo:"T15",service:"10",startDate:"26-02-16 10:20",appId:"G12999"]
]
col1
.findAll { it.cuInfo in col2.cuInfo && !(it.subMap('cuInfo', 'service', 'startDate', 'appId') in col2) }
.collect {
def e = col2.find { i2 -> it.cuInfo == i2.cuInfo }
it << [startDate2: e.startDate, appId2: e.appId]
}
.each {
println it
}
?
devices :[1.1:Acer C6, 2:Acer C6, 1:Acer C6, 2.2:HTC Magic]
files :[2:Tetris.apk, 1:TheSims3.apk]
I have a mapping of files and devies, as of now its one-to-many mapping.
devices :[1.1:Acer C6, 2:Acer C6, 1:Acer C6, 2.2:HTC Magic]
files :[2:Tetris.apk, 1:TheSims3.apk]
Now I need to implement many-to-many mapping
my logic for one-to-many mapping is
mapping = params.devices.inject( [:] ) { map, dev ->
// Get the first part of the version (up to the first dot)
def v = dev.key.split( /\./ )[ 0 ]
logger.debug("value of v :"+v)
map << [ (dev.value): files[ v ] ]
}
current output is - mapping :[Acer C6:Tetris.apk, HTC Magic:Tetris.apk]
expected output : [Acer C6:Tetris.apk, Acer C6:TheSims3.apk, HTC Magic:Tetris.apk]
You are accumulating your results using the device name as a key. When a new value is added to the map, it overwrites the last one with the same key.
You could try accumulating into a Set instead of a map. Example:
def devices = ['1.1': 'Acer C6', '2': 'Acer C6', '1': 'Acer C6', '2.2': 'HTC Magic']
def files = ['2': 'Tetris.apk', '1': 'TheSims3.apk']
def deviceFiles = devices.inject([] as Set) { deviceFiles, device ->
def v = device.key.split( /\./ )[0]
deviceFiles << [ (device.value), files[ v ] ]
}
assert deviceFiles == [
['Acer C6', 'Tetris.apk'],
['Acer C6', 'TheSims3.apk'],
['HTC Magic', 'Tetris.apk']
] as Set